如何处理问题的答案?

huangapple go评论86阅读模式
英文:

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(&quot;handler&quot;, zap.Reflect(&quot;HandleView&quot;, update))

	smileSearch := &quot;\xF0\x9F\x94\x8E\t&quot;

	text := fmt.Sprintf(&quot;%v &lt;b&gt;Please enter phrase&lt;/b&gt;\n\n&quot;, smileSearch)

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

	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>

huangapple
  • 本文由 发表于 2022年3月26日 02:29:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/71621590.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定