mtcute/docs/guide/topics/inline-mode.md
alina sireneva 690948b8b1
All checks were successful
Build and deploy typedoc / build (push) Successful in 5m15s
chore: moved docs inside the main repo
Co-authored-by: Kamilla 'ova <me@kamillaova.dev>
Co-authored-by: Alina Chebakova <chebakov05@gmail.com>
Co-authored-by: Kravets <57632712+kravetsone@users.noreply.github.com>
Co-authored-by: starkow <hello@starkow.dev>
Co-authored-by: sireneva <150665887+sireneva@users.noreply.github.com>
2025-01-17 08:50:35 +03:00

1.3 KiB
Executable file

Inline mode

Users can interact with bots using inline queries, by starting a message with bot's username and then typing their query.

Implementing inline mode

First, you'll need to enable inline mode in @BotFather, either in /mybots or with /setinline

Then, you can use Dispatcher to implement inline mode for your bot.

Instead of Dispatcher, you can also use client events (however you will miss features that Dispatcher provides):

tg.on('inline_query', async (query) => {
    await query.answer([])
})

Using inline mode

As a user, you can use inline mode just like with a normal client.

It is currently not implemented as a Client method, but you can use Raw API:

const chat = await tg.resolvePeer('me')

const results = await tg.call({
    _: 'messages.getInlineBotResults',
    bot: toInputUser(await tg.resolvePeer('music'))!,
    peer: chat,
    query: 'vivaldi',
    offset: ''
}, { throw503: true })

Then, for example, to send the first result:

const first = results.results[0]

const res = await tg.call({
    _: 'messages.sendInlineBotResult',
    peer: chat,
    randomId: randomLong(),
    queryId: results.queryId,
    id: first.id
})
tg.handleClientUpdate(res, true)