【问题标题】:Telegram Bots - inline mode电报机器人 - 内联模式
【发布时间】:2023-03-13 08:17:01
【问题描述】:

我需要在内联模式下使用机器人,并且我正在使用 java 开源库来处理对电报 API 的 RESTful 请求。该库可在此链接https://github.com/pengrad/java-telegram-bot-api 中找到。我试着这样做:

String query = inlineQuery.query().trim().toLowerCase();
List<String> answerList = new LinkedList<String>();
answerList.add("first_answer");
answerList.add("second_answer");
InlineQueryResult[] resArray = new InlineQueryResult[answerList.size()];
for (int j = 0; j < resArray.length; j++)}{ 
    resArray[j] = new InlineQueryResultArticle(inlineQuery.id(), answerList.get(j), query);
}
bot.answerInlineQuery(inlineQuery.id(), resArray);

但我在运行时有这个异常

Exception in thread "main" retrofit.RetrofitError: 400 Bad Request

我将InlineQueryResultArticle 构造函数的第一个参数从inlineQuery.id() 编辑为"id_"+j,现在它可以工作了。

【问题讨论】:

标签: java telegram telegram-bot


【解决方案1】:

尝试使用 2.0.0 版本的库。 现在在响应对象中返回错误消息。 并且有一个 API 变化

【讨论】:

  • 谢谢,我正在使用新版本的库,我对响应的描述如下:Bad Request: RESULT_ID_DUPLICATE我将最后一行代码替换为BaseResponse response = bot.execute(new AnswerInlineQuery(inlineQuery.id(), resArray));
  • @chris 你应该为InlineQueryResultArticle 使用唯一ID,例如new InlineQueryResultArticle(j, answerList.get(j), query);
猜你喜欢
  • 2016-09-11
  • 2020-07-09
  • 2017-08-18
  • 2017-12-10
  • 1970-01-01
  • 2022-01-01
  • 1970-01-01
  • 2019-03-27
  • 1970-01-01
相关资源
最近更新 更多