-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
82 lines (66 loc) · 2.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require('dotenv').config()
const settings = require('./settings')
const { Configuration, OpenAIApi } = require('openai')
const configuration = new Configuration({
organization: process.env.OPENAI_ORG_ID,
apiKey: process.env.OPENAI_TOKEN
})
const openai = new OpenAIApi(configuration)
const { create } = require('venom-bot')
const { checkPhoneNumber } = require('./helper')
const {
getDavinciResponse,
getDalleResponse,
getJsResponse
} = require('./tools')
const commands = async (client, message) => {
if (!message.hasOwnProperty("text") && message.type !== "chat") return;
const iaCommands = {
davinci3: settings.davinci_trigger,
dalle: settings.dalle_trigger,
jshelper: settings.jshelper_trigger
}
const {text} = message
const question = text.substring(text.indexOf(" "))
const firstWord = text.substring(0, text.indexOf(" "))
const destinationNumber = checkPhoneNumber(message)
switch (firstWord) {
case iaCommands.davinci3:
getDavinciResponse(question, openai)
.then( response => {
client.sendText(destinationNumber, response)
})
break
case iaCommands.dalle:
const imgDescription = question
getDalleResponse(imgDescription, openai)
.then(imgUrl => {
client.sendImage(
destinationNumber,
imgUrl,
imgDescription,
settings.dalle_text
)
})
break
case iaCommands.jshelper:
getJsResponse(question, openai)
.then(response => {
client.sendText(destinationNumber, response)
})
break
}
}
create({
session: 'chat-gpt',
multidevice: true
})
.then((client) => start(client))
.catch((erro) => {
console.error(erro)
})
async function start(client) {
client.onAnyMessage(message => {
commands(client, message)
})
}