Telegram Inline Query
Allows you to receive and answer an inline query from Telegram.
Read more information about inlineQuery here, and before starting, it is necessary that this mode needs to be enabled in Telegram.
Configuration
Define the context that will receive inline queries, by modify the field bellow in config/platforms/telegram.rb
configuration file.
Send Answers
In order to send answers to an inline query, call @reply.inline_query_result()
method:
inline_query_result(type=Symbol, answer=Hash)
inline_query_result(type=Symbol, answer=Hash)
Params
Name | Description |
---|---|
| Required. Can be |
| Required. The answer, that varies depending on the type defined, read about the response formats for each type on Telegram documentation. |
Usage
When an inline query arrives, the configured context will handle it, through action blocks that capture text messages such as keyword
, intent
, entity
, any_text
and so on.
In the next example, we've created a context called NewsContext
, which has been configured to handle inline queries as follows:
This context will call two keyword blocks with the arguments "nytimes"
and "cnn"
respectively. Each of them will return news extracted from the RSS service from the The New York Times or CNN.
To implement this example you'll need to add the gems feedjira
and httparty
to the project's Gemfile.
How would it look?
Shared content
In the example above, html_template("news/preview", {article: article})
has been called, this method loads a template from bot/templates/news/preview.rhtml
with the following code:
This content is what the person with whom the user is sharing the article will receive.
Learn more about html_template()
method here.
Last updated