-
-
Save zaz600/b377834ef863de563bb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/Syfaro/telegram-bot-api" | |
"log" | |
) | |
func main() { | |
// подключаемся к боту с помощью токена | |
bot, err := tgbotapi.NewBotAPI("ТОКЕН") | |
if err != nil { | |
log.Panic(err) | |
} | |
bot.Debug = true | |
log.Printf("Authorized on account %s", bot.Self.UserName) | |
// инициализируем канал, куда будут прилетать обновления от API | |
var ucfg tgbotapi.UpdateConfig = tgbotapi.NewUpdate(0) | |
ucfg.Timeout = 60 | |
err = bot.UpdatesChan(ucfg) | |
// читаем обновления из канала | |
for { | |
select { | |
case update := <-bot.Updates: | |
// Пользователь, который написал боту | |
UserName := update.Message.From.UserName | |
// ID чата/диалога. | |
// Может быть идентификатором как чата с пользователем | |
// (тогда он равен UserID) так и публичного чата/канала | |
ChatID := update.Message.Chat.ID | |
// Текст сообщения | |
Text := update.Message.Text | |
log.Printf("[%s] %d %s", UserName, ChatID, Text) | |
// Ответим пользователю его же сообщением | |
reply := Text | |
// Созадаем сообщение | |
msg := tgbotapi.NewMessage(ChatID, reply) | |
// и отправляем его | |
bot.SendMessage(msg) | |
} | |
} | |
} |
Have the same issue on Mac OS X.
.\ go-tg-bot.go:22: bot.UpdatesChan undefined (type *tgbotapi.BotAPI has no field or method UpdatesChan)
.\ go-tg-bot.go:26: bot.Updates undefined (type *tgbotapi.BotAPI has no field or method Updates)
.\ go-tg-bot.go:45: bot.SendMessage undefined (type *tgbotapi.BotAPI has no field or method SendMessage)
same here code is not working
Simple changes for build below. But it's no tested in work.
// подключаемся к боту с помощью токена
bot, err := tgbotapi.NewBotAPI("TOKEH")
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
// инициализируем канал, куда будут прилетать обновления от API
var ucfg tgbotapi.UpdateConfig = tgbotapi.NewUpdate(0)
ucfg.Timeout = 60
upd, _ := bot.GetUpdatesChan(ucfg)
// читаем обновления из канала
for {
select {
case update := <-upd:
// Пользователь, который написал боту
UserName := update.Message.From.UserName
// ID чата/диалога.
// Может быть идентификатором как чата с пользователем
// (тогда он равен UserID) так и публичного чата/канала
ChatID := update.Message.Chat.ID
// Текст сообщения
Text := update.Message.Text
log.Printf("[%s] %d %s", UserName, ChatID, Text)
// Ответим пользователю его же сообщением
reply := Text
// Созадаем сообщение
msg := tgbotapi.NewMessage(ChatID, reply)
// и отправляем его
bot.Send(msg)
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
under linux arm with go arm build :
looks like there is a problem in telegram-bot-API