Home > Software design >  How do I process the answer to a question?
How do I process the answer to a question?

Time:03-28

My handler callback:

func (b *Bot) HandleView(bot *tgbotapi.BotAPI, update tgbotapi.Update) error {
    zap.L().Debug("handler", zap.Reflect("HandleView", update))

    smileSearch := "\xF0\x9F\x94\x8E\t"

    text := fmt.Sprintf("%v <b>Please enter phrase</b>\n\n", smileSearch)

    msg := tgbotapi.NewMessage(update.CallbackQuery.From.ID, text)
    msg.ParseMode = "html"

    if _, err := bot.Send(msg); err != nil {
        return err
    }

    return nil
}

I need the user input to be processed in a separate handler. How to do it on golang ?

UPD:
When the HandleView function runs, the user has to enter something. How do I set a handler for this input?

UPD2: i used golang and "github.com/go-telegram-bot-api/telegram-bot-api/v5"

CodePudding user response:

You should get updates from the telegram server by one of two methods, polling or webhook. Each pair is explained on the GitHub page with an example.

Also, you may need to make a connection between the reply from the user and the message you sent. for example, you can save your message's id that was obtained after sending and ask the user to send his answer by using the reply feature to your message. Then you can tell from comparing MessageID that the answer is related to that message.

  • Related