Telegram Bot Utilities – examples: Inline Query
In this article you can see an example of inline query that returns two images when you send a query equal to “photo”.
public static void main(String[] args) { TelegramBot b = new TelegramBot("<your-token>"); Update u, ar[]; while (true) { try { int updateId = b.getCurrentUpdateId(); if (updateId < 0) { ar = b.getUpdates(updateId, 0, 0); u = ar[ar.length - 1]; if (u.getQuery() != null) { System.out.println(u.getQuery().getQuery()); if (u.getQuery().getQuery().compareTo("photo") == 0) { InlineQueryResultPhoto[] p = new InlineQueryResultPhoto[2]; p[0] = new InlineQueryResultPhoto("0", "urlToYourImage", "urlToYourThumbnail"); p[1] = new InlineQueryResultPhoto("1", "urlToYourImage", "urlToYourThumbnail"); b.answerInlineQuery(u.getQuery().getId(), p); } } } } catch (EmptyUpdatesException e) { e.printStackTrace(); } catch (GettingUpdatesException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
Here you can see the result