-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateGroup.go
77 lines (67 loc) · 2.67 KB
/
createGroup.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
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
package scenes
import (
chatbot "github.com/green-api/whatsapp-chatbot-golang"
"github.com/green-api/whatsapp-demo-chatbot-golang/util"
)
type CreateGroupScene struct {
}
func (s CreateGroupScene) Start(bot *chatbot.Bot) {
bot.IncomingMessageHandler(func(message *chatbot.Notification) {
if !util.IsSessionExpired(message) {
lang := message.GetStateData()["lang"].(string)
text, _ := message.Text()
senderId, _ := message.Sender()
switch text {
case "1":
group, err := message.GreenAPI.Methods().Groups().CreateGroup(
util.GetString([]string{"group_name", lang}),
[]string{senderId})
if err != nil {
*message.ErrorChannel <- err
}
var groupId = group["chatId"].(string)
message.StateManager.Create(groupId)
message.StateManager.UpdateStateData(groupId, message.GetStateData())
message.StateManager.ActivateNextScene(groupId, EndpointsScene{})
resp, err := message.GreenAPI.Methods().Groups().SetGroupPicture(
"assets/Group_avatar.jpg",
groupId)
if err != nil {
*message.ErrorChannel <- err
}
if resp["setGroupPicture"].(bool) {
_, err := message.GreenAPI.Methods().Sending().SendMessage(map[string]interface{}{
"chatId": groupId,
"message": util.GetString([]string{"send_group_message", lang}) + util.GetString([]string{"links", lang, "groups_documentation"})})
if err != nil {
bot.ErrorChannel <- err
}
} else {
_, err := message.GreenAPI.Methods().Sending().SendMessage(map[string]interface{}{
"chatId": groupId,
"message": util.GetString([]string{"send_group_message_set_picture_false", lang}) + util.GetString([]string{"links", lang, "groups_documentation"})})
if err != nil {
bot.ErrorChannel <- err
}
}
message.SendText(util.GetString([]string{"group_created_message", lang}) +
group["groupInviteLink"].(string))
message.ActivateNextScene(EndpointsScene{})
case "menu", "меню", "Menu", "Меню", "0":
var welcomeFileURL string
if lang == "en" {
welcomeFileURL = "https://raw.githubusercontent.com/green-api/whatsapp-demo-chatbot-golang/refs/heads/master/assets/welcome_en.jpg"
} else {
welcomeFileURL = "https://raw.githubusercontent.com/green-api/whatsapp-demo-chatbot-golang/refs/heads/master/assets/welcome_ru.jpg"
}
message.SendUrlFile(welcomeFileURL, "welcome.jpg", util.GetString([]string{"menu", lang}))
bot.ActivateNextScene(message.StateId, EndpointsScene{})
default:
message.SendText(util.GetString([]string{"not_recognized_message", lang}))
}
} else {
message.ActivateNextScene(MainMenuScene{})
message.SendText(util.GetString([]string{"select_language"}))
}
})
}