skip to Main Content

I’d like to push a formatted message to to clients from my bot in much the same way as the Durger King app does. In response to any input to the bot a message showing for formatted ‘Let’s get started’ is displayed along with a picture. Underneath there is order food WebApp button which opens the PWA.

Is this simply and image or is it formatted HTML, which would possibly be easier to manage.

How can one send either a an image or formatted HTML using the telego Go bot.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    Here's what is probably the wrong way of achieving this:

    var (helloMsg    = &tele.Message{Text: "<b>Let's get started!</b>🍟"})
    
    func main() {   
    pref := tele.Settings{
        Token:  os.Getenv("TOKEN"),
        Poller: &tele.LongPoller{Timeout: 5 * time.Second},
    }
    
    b, err := tele.NewBot(pref)
    if err != nil {
        log.Fatal(err)
        return
    }
    
        b.Handle("/start", func(c tele.Context) error {
        log.Println("Detected Start")
        b.Send(c.Message().Sender, helloMsg.Text, &tele.SendOptions{
            ParseMode: "HTML",
        }, webapp)
        return nil
    })}
    }
    

    I haven't tried to see if it is possible to use the context instead of the bot itself, and returning nil probably isn't a great idea. But essentially you this is setting the ParseMode to HTML and somehow the emoji can be pasted in...

    This is what it looks like:

    enter image description here


  2. Here’s the version using the context:

    b.Handle("/start", func(c tele.Context) error {
        log.Println("Detected Start")
        b.Send(c.Message().Sender, helloMsg.Text, &tele.SendOptions{
            ParseMode: "HTML",
        }, webapp)
        return nil
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search