Yurst

Inline queries

Handling @bot query and offering results

Inline queries

Inline mode allows a user to invoke the bot from any chat by typing @bot_username query.

How it works

  1. The user types @mybot search
  2. Yurba sends an inline query to the bot
  3. The bot responds with a list of results
  4. The user selects a result, which is sent to the chat

InlineContext

Passed to bot.on('inline').

Fields

FieldTypeDescription
ctx.updateobjectRaw update
ctx.userobject | nullThe user who made the request
ctx.querystringRequest text after the bot name

Methods

answer(results)

Responds to the query with a list of results.

bot.on('inline', (ctx) => {
  if (!ctx.query) return;

  return ctx.answer([
    { id: '1', title: 'Ехо', text: ctx.query },
    { id: '2', title: 'Великі літери', text: ctx.query.toUpperCase() },
  ]);
});

Result format

Each result is an object with the fields:

FieldRequiredDescription
idno*Unique result ID
titleyesTitle in the list
textyesMessage text when selected

* If id is not passed, Yurst generates a random one.

Record format

Yurst accepts both variants:

camelCasePascalCase
idID
titleTitle
textText
// Обидва варіанти еквівалентні:
ctx.answer([{ id: '1', title: 'Test', text: 'Hello' }]);
ctx.answer([{ ID: '1', Title: 'Test', Text: 'Hello' }]);

Example: Transformations

bot.on('inline', (ctx) => {
  const q = ctx.query.trim();
  if (!q) return;

  return ctx.answer([
    { id: 'upper', title: 'Великі літери', text: q.toUpperCase() },
    { id: 'lower', title: 'Малі літери', text: q.toLowerCase() },
    { id: 'reverse', title: 'Реверс', text: [...q].reverse().join('') },
  ]);
});
const PRODUCTS = [
  { id: 1, name: 'iPhone 15', price: 999 },
  { id: 2, name: 'MacBook Pro', price: 1999 },
  { id: 3, name: 'iPad Pro', price: 799 },
  { id: 4, name: 'AirPods Pro', price: 249 },
];

bot.on('inline', (ctx) => {
  const q = ctx.query.toLowerCase().trim();
  if (!q) return;

  const filtered = PRODUCTS.filter(p =>
    p.name.toLowerCase().includes(q),
  );

  const results = filtered.map(p => ({
    id: String(p.id),
    title: p.name,
    text: `${p.name} — $${p.price}`,
  }));

  return ctx.answer(results);
});

The inline_sent event

When a user selects a result, the bot receives an inline_sent event:

bot.on('inline_sent', (update) => {
  console.log('Результат вибрано:', update);
  // update.Inline — інформація про вибраний результат
  // update.User — хто вибрав
});

The handler receives the raw update object, not a context.

Always check ctx.query for an empty value. Empty queries are best ignored.

Limitations

  • Results are visible only to the user who made the request
  • There is a limit on the number of results (usually ~50)
  • The response timeout is a few seconds

Next

Events

All event types and their handling

On this page