【发布时间】: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,现在它可以工作了。
【问题讨论】:
-
您是否完成了使用 Botfather 创建令牌的步骤?您的代码是否使用该令牌? core.telegram.org/bots#6-botfather
-
是的,这些步骤已经完成。
标签: java telegram telegram-bot