Last active
October 6, 2015 08:03
-
-
Save Negaihoshi/f7d3ef2161492b6a46b9 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 ( | |
"fmt" | |
"log" | |
"github.com/Syfaro/telegram-bot-api" | |
"github.com/gin-gonic/gin" | |
) | |
func main() { | |
channel := make(chan string) | |
router := gin.Default() | |
router.GET("/", func(c *gin.Context) { | |
message := c.Query("message") | |
fmt.Println(message) | |
channel <- message | |
}) | |
bot, err := tgbotapi.NewBotAPI("139199147:AAFb6XeGxCGyS_OJuPvSyw2rKto_oWpszs0") | |
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 | |
err = bot.UpdatesChan(u) | |
if err != nil { | |
log.Panic(err) | |
} | |
go func() { | |
for update := range bot.Updates { | |
update := update | |
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) | |
// message := <-channel | |
// msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) | |
// msg.ReplyToMessageID = update.Message.MessageID | |
// fmt.Println("=======================") | |
// fmt.Println(msg) | |
fmt.Println("=======================") | |
select { | |
case message := <-channel: | |
fmt.Println("received message", message) | |
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "A test message from the test library in telegram-bot-api") | |
bot.SendMessage(msg) | |
default: | |
fmt.Println("no activity") | |
msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) | |
bot.SendMessage(msg) | |
} | |
} | |
}() | |
router.Run(":8080") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment