Fix example

This commit is contained in:
Hamcha 2018-12-13 10:48:36 +01:00
parent 10ef1429c3
commit 487ffb1bf7
Signed by: hamcha
GPG key ID: A40413D21021EAEE

View file

@ -1,15 +1,19 @@
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() {
CreateBrokerClient("localhost:7314", func(broker *Broker, message APIMessage) {
tg.CreateBrokerClient("localhost:7314", func(broker *tg.Broker, update tg.APIUpdate) {
// Check if it's a text message
if message.Text != nil {
if update.Message != nil && update.Message.Text != nil {
// Check that it's a greeting
if *(message.Text) == "hello" || *(message.Text) == "hi" {
if *(update.Message.Text) == "hello" || *(update.Message.Text) == "hi" {
// Reply with a greeting!
broker.SendTextMessage(message.Chat, "Hello!", message.MessageID)
broker.SendTextMessage(update.Message.Chat, "Hello!", &tg.MessageOptions{
ReplyID: &update.Message.MessageID,
})
}
}
})