gpt4 book ai didi

go - 处理用户回答

转载 作者:行者123 更新时间:2023-12-01 22:20:30 26 4
gpt4 key购买 nike

任务是用户输入一笔存款,我可以在这种情况下处理它,但不像一个简单的命令。 示例:
введите сюда описание изображения
我的代码:

func main () {
testing()
NewBot, BotError = tgBotApi.NewBotAPI(configuration.BOT_TOKEN)
if BotError != nil {
fmt.Println(BotError.Error())
}
NewBot.Debug = true
fmt.Println("OK", time.Now().Unix(), time.Now(), time.Now().Weekday())
setWebhook(NewBot)
updates := NewBot.ListenForWebhook("/" + configuration.BOT_TOKEN)
//go successfulPaymentListen()
go http.ListenAndServeTLS(fmt.Sprintf("%s:%s", configuration.BOT_HOST, configuration.BOT_PORT), configuration.CERT_FILE, configuration.CERT_KEY, nil)
for update := range updates {

if update.Message != nil {
recognizeCommand(update)
} else if update.CallbackQuery != nil {
if update.CallbackQuery.Data == "/addFunds crypto" {
get_data.AddFundsChooseCurrencyCrypto(update, NewBot)
} else if update.CallbackQuery.Data == "/addFunds qiwi" {
get_data.AddFundsChooseCurrencyQiwi(update, NewBot)
} else if strings.Split(update.CallbackQuery.Data, " ")[2] != "" {
get_data.AddFundsChooseCurrencyCurrentCrypto(update, NewBot, strings.Split(update.CallbackQuery.Data, " ")[2])
//This function is below
}
}
}
}
get_data.AddFundsChooseCurrencyCurrentCrypto:
func AddFundsChooseCurrencyCurrentCrypto(update tgBotApi.Update, NewBot *tgBotApi.BotAPI, currency string) {
chatUser := int64(update.CallbackQuery.From.ID)
msg := tgBotApi.NewMessage(chatUser, "Input a sum of deposit:")
NewBot.Send(msg)
//There is I have to handle user answer, but I can't override ListenWebHook
}
问题是我需要 ListenWebHook localy(在函数 AddFundsChooseCurrencyCurrentCrypto 中)而不是主函数
------------------------ 更新 ------------------------
我试过这个代码:
func AddFundsChooseCurrencyCurrentCrypto(update tgBotApi.Update, NewBot *tgBotApi.BotAPI, currency string) {
chatUser := int64(update.CallbackQuery.From.ID)
msg := tgBotApi.NewMessage(chatUser, "Input a sum of deposit:")
NewBot.Send(msg)
NewBotContext, BotError := tgBotApi.NewBotAPI(configuration.BOT_TOKEN)
if BotError != nil {
log.Panic(BotError.Error())
}
updates := NewBotContext.ListenForWebhook("/" + configuration.BOT_TOKEN)
for update := range updates {
fmt.Println(update)
}
}
但是错误:
panic: http: multiple registrations for /mytokenbot

goroutine 1 [running]:
net/http.(*ServeMux).Handle(0xe38620, 0xc25304, 0x2f, 0xc7dbe0, 0xc00018bec0)

最佳答案

您已尝试使用路由器两次注册相同的 url '/mytokenbot'。您可以在 net/http 中找到错误:
https://golang.org/src/net/http/server.go#L2433
在 mux Handle 函数中。
因此,只需使用servemux查看您的注册函数代码,并检查您可能如何调用它两次。

关于go - 处理用户回答,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63858149/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com