-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.go
49 lines (37 loc) · 944 Bytes
/
Bot.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
package main
import "fmt"
import (
"log"
"github.com/go-telegram-bot-api/telegram-bot-api"
)
const token = "YOUR TOKEN"
func main() {
// Connect to Bot via Token
bot, err := tgbotapi.NewBotAPI(token)
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil {
bot.Send(tgbotapi.NewMessage(update.Message.Chat.ID, "NOT FOUND"))
continue
}
if update.Message.NewChatMembers != nil {
member := (*update.Message.NewChatMembers)[0]
var name string
if member.UserName != "" {
name = member.UserName
} else {
name = member.FirstName + " " + member.LastName
}
var greetings = fmt.Sprintf("Hello %s!", name)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, greetings)
bot.Send(msg)
}
}
}