tg/client_test.go

21 lines
756 B
Go
Raw Normal View History

2018-04-03 09:51:06 +00:00
package tg_test
2018-12-13 09:48:36 +00:00
import "git.fromouter.space/hamcha/tg"
2018-04-03 09:51:06 +00:00
// This example creates a basic client that connects to a broker and checks for message containing greetings.
// If it finds a greeting message it will greet back the user (using the reply_to parameter)
func ExampleCreateBrokerClient() {
2018-12-13 09:48:36 +00:00
tg.CreateBrokerClient("localhost:7314", func(broker *tg.Broker, update tg.APIUpdate) {
2018-04-03 09:51:06 +00:00
// Check if it's a text message
2018-12-13 09:48:36 +00:00
if update.Message != nil && update.Message.Text != nil {
2018-04-03 09:51:06 +00:00
// Check that it's a greeting
2018-12-13 09:48:36 +00:00
if *(update.Message.Text) == "hello" || *(update.Message.Text) == "hi" {
2018-04-03 09:51:06 +00:00
// Reply with a greeting!
2018-12-13 09:48:36 +00:00
broker.SendTextMessage(update.Message.Chat, "Hello!", &tg.MessageOptions{
ReplyID: &update.Message.MessageID,
})
2018-04-03 09:51:06 +00:00
}
}
})
}