-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (43 loc) · 1.14 KB
/
main.go
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
package main
import (
"log"
chatbot "github.com/green-api/whatsapp-chatbot-golang"
"github.com/green-api/whatsapp-demo-chatbot-golang/scenes"
"github.com/joho/godotenv"
)
func main() {
idInstance := "{idInstance}"
authToken := "{authToken}"
envFile, err := godotenv.Read("instance.env")
if err == nil {
if val, exists := envFile["idInstance"]; exists && len(val) > 0 {
idInstance = val
}
if val, exists := envFile["authToken"]; exists && len(val) > 0 {
authToken = val
}
}
if idInstance == "{idInstance}" || authToken == "{authToken}" {
log.Fatal("No idInstance or authToken set")
}
bot := chatbot.NewBot(idInstance, authToken)
go func() {
for err := range bot.ErrorChannel {
if err != nil {
log.Println(err)
}
}
}()
_, err = bot.GreenAPI.Methods().Account().SetSettings(map[string]interface{}{
"incomingWebhook": "yes",
"outgoingMessageWebhook": "yes",
"outgoingAPIMessageWebhook": "yes",
"pollMessageWebhook": "yes",
"markIncomingMessagesReaded": "yes",
})
if err != nil {
bot.ErrorChannel <- err
}
bot.SetStartScene(scenes.StartScene{})
bot.StartReceivingNotifications()
}