new folder and file folder: go/tg file go/tg/l1.go for sending message in chat telegram bot
This commit is contained in:
parent
a7966f694a
commit
2dd1213e09
5 changed files with 42 additions and 0 deletions
|
|
@ -1,2 +1,4 @@
|
|||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
|
||||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
|
|
|
|||
1
go/tg/.gitignore
vendored
Normal file
1
go/tg/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
.env
|
||||
4
go/tg/go.sum
Normal file
4
go/tg/go.sum
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
|
||||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
35
go/tg/l1.go
Normal file
35
go/tg/l1.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/joho/godotenv"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("%v\n", err)
|
||||
}
|
||||
tg := os.Getenv("TG_TOKEN")
|
||||
bot, err := tgbotapi.NewBotAPI(tg)
|
||||
if err != nil {
|
||||
log.Fatalf("%v\n", err)
|
||||
}
|
||||
bot.Debug = true
|
||||
fmt.Printf("Работает как %s", bot.Self.UserName)
|
||||
u := tgbotapi.NewUpdate(0)
|
||||
u.Timeout = 60
|
||||
upd := bot.GetUpdatesChan(u)
|
||||
for update := range upd {
|
||||
if update.Message == nil {
|
||||
continue
|
||||
}
|
||||
if update.Message.IsCommand() && update.Message.Command() == "start" {
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Сергей")
|
||||
bot.Send(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
go/tg/output/l1
Executable file
BIN
go/tg/output/l1
Executable file
Binary file not shown.
Loading…
Reference in a new issue