英文:
How do I process the answer to a question?
问题
我的处理程序回调:
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
}
我需要将用户输入在单独的处理程序中处理。如何在golang中实现?
更新:
当HandleView函数运行时,用户必须输入一些内容。如何为此输入设置处理程序?
更新2:
我使用了golang和"github.com/go-telegram-bot-api/telegram-bot-api/v5"。
英文:
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"
答案1
得分: 1
你应该通过两种方法之一从Telegram服务器获取更新,即轮询或Webhook。每对方法在GitHub页面上都有解释和示例。
此外,你可能需要建立用户回复和你发送的消息之间的连接。例如,你可以保存发送后获得的消息ID,并要求用户使用回复功能将答案发送给你的消息。然后,通过比较消息ID,你可以确定答案与该消息相关联。
英文:
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.
<i>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.</i>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论