我如何让我的机器人用参数来回应? [英] How do I have my Bot respond with arguments?

查看:31
本文介绍了我如何让我的机器人用参数来回应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我构建了一个 Telegram bot,它可以接收以下命令:

So I've built a Telegram bot, which can receive the following commands:

  • /list
  • /info 123

这很好用,因为我可以捕获 /info 并将附加参数作为整数传递.但是,遗憾的是,Telegram 客户端没有将 /info 123 视为一个完整的命令,而只是将 /info 部分视为.有没有办法让它将整个命令识别为命令?

This works great, as I can catch /info and pass the additional arguments as ints. But, sadly, the Telegram clients don't see /info 123 as a complete command, but just the /info part. Is there a way to make it recognize the entirety of the command as the command?

我已经尝试过 Markdown-ing:[/info 123](/info 123),但没有任何乐趣.这可能吗?

I've tried Markdown-ing it: [/info 123](/info 123), but no joy. Is this possible?

推荐答案

我已经向@BotSupport 提出了同样的问题,他/他们/它迅速回复了以下答案:

I've reached out to @BotSupport with the same question, and he/they/it responded swiftly with the following answer:

您好,目前无法突出显示命令的参数.无论如何,如果您使用正确的自定义键盘,您可以找到解决方法;)—@BotSupport

Hi, at the moment it is not possible to highlight parameters of a command. I any case, you may can find a workaround if you use correct custom keyboards ;) — @BotSupport

自定义键盘可能适合某些人,但不适合我.我采用的解决方案是将命令指定为 /info123.当机器人收到所有 / 命令时,我检查接收到的命令是否以 info 开头,如果是,则删除 info 部分.我将剩余的 string/int 转换为参数,并将其传递给相关命令.

Custom keyboards may be an option for someone, but not for me. The solution I've gone for is to give the command as /info123. As the bot receives all / commands, I check if the received command starts with info, and if so, I remove the info part. I convert the remaining string/int to arguments, and pass that along to the relevant command.

这篇关于我如何让我的机器人用参数来回应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆