This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messageHandler.go
82 lines (63 loc) · 1.86 KB
/
messageHandler.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
78
79
80
81
82
package wabot
import (
"fmt"
"os"
"strings"
"time"
"github.com/Rhymen/go-whatsapp"
)
type messageHandler struct{}
/*
TODO Use custom Handlers from custom Bots
*/
// Mainly caused by another instance of Whatsapp Web being opened
func (messageHandler) HandleError(err error) {
if !strings.Contains(err.Error(), "error processing data") {
if errorTimeout == -1 {
fmt.Printf("Exit due to connection break. Error:%s\n", err.Error())
os.Exit(0)
}
// Reconnect after a given amount of time
fmt.Printf("WhatsApp crashed with the following Message:\n%s\nTrying again in: %d\n", err.Error(), errorTimeout)
time.Sleep(errorTimeout)
conn.Disconnect()
err = nil
session, conn, err = handleLogin()
if err != nil {
fmt.Println("--- Connected again! ---")
} else {
fmt.Println("Reconnect error: ", err.Error())
os.Exit(1)
}
}
}
func (messageHandler) HandleTextMessage(message whatsapp.TextMessage) {
if message.Info.Timestamp > startTime {
go handleBotMsg(message)
if showTextMessages {
fmt.Printf("%s: %s\n", JidToGroupName(message.Info.RemoteJid), message.Text)
}
}
}
func (messageHandler) HandleImageMessage(message whatsapp.ImageMessage) {
if message.Info.Timestamp > startTime {
go imageHandleFunction(message)
}
}
func (messageHandler) HandleDocumentMessage(message whatsapp.DocumentMessage) {
//fmt.Println(message)
}
func (messageHandler) HandleVideoMessage(message whatsapp.VideoMessage) {
//fmt.Println(message)
}
func (messageHandler) HandleAudioMessage(message whatsapp.AudioMessage) {
//fmt.Println(message)
}
func (messageHandler) HandleJSONMessage(message string) {
// fmt.Println(message)
}
func (messageHandler) HandleStickerMessage(message whatsapp.StickerMessage) {
if message.Info.Timestamp > startTime && strings.Contains(message.Info.Source.Message.String(), "url:") {
go stickerHandleFunction(message)
}
}