20 lines
756 B
Go
20 lines
756 B
Go
package tg_test
|
|
|
|
import "git.fromouter.space/hamcha/tg"
|
|
|
|
// 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() {
|
|
tg.CreateBrokerClient("localhost:7314", func(broker *tg.Broker, update tg.APIUpdate) {
|
|
// Check if it's a text message
|
|
if update.Message != nil && update.Message.Text != nil {
|
|
// Check that it's a greeting
|
|
if *(update.Message.Text) == "hello" || *(update.Message.Text) == "hi" {
|
|
// Reply with a greeting!
|
|
broker.SendTextMessage(update.Message.Chat, "Hello!", &tg.MessageOptions{
|
|
ReplyID: &update.Message.MessageID,
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|