-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
48 lines (40 loc) · 957 Bytes
/
app.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
package main
import (
"context"
"fmt"
"go.mau.fi/whatsmeow/types"
waProto "go.mau.fi/whatsmeow/binary/proto"
"google.golang.org/protobuf/proto"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) WhatsAppStart() {
wac, err := WAConnect()
if err != nil {
fmt.Println(err)
}
defer wac.Disconnect()
}
func (a *App) SendMessage(phone string, message string) string {
_, err := cli.SendMessage(context.Background(),types.JID{
User: phone,
Server: types.DefaultUserServer,
}, &waProto.Message{
Conversation: proto.String(message),
})
if err != nil {
fmt.Println(err)
}
return fmt.Sprintf("Message: \"%s\" successfully sended to the number %s!", message, phone)
}