forked from telegraf/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline-bot.js
More file actions
29 lines (24 loc) · 865 Bytes
/
inline-bot.js
File metadata and controls
29 lines (24 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const Telegraf = require('telegraf')
const fetch = require('node-fetch')
// async/await example.
async function omdbSearch (query = '') {
const apiUrl = `http://www.omdbapi.com/?s=${query}&apikey=9699cca`
const response = await fetch(apiUrl)
const json = await response.json()
const posters = (json.Search && json.Search) || []
return posters.filter(({ Poster }) => Poster && Poster.startsWith('https://')) || []
}
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.on('inline_query', async ({ inlineQuery, answerInlineQuery }) => {
const posters = await omdbSearch(inlineQuery.query)
const results = posters.map((poster) => ({
type: 'photo',
id: poster.imdbID,
caption: poster.Title,
description: poster.Title,
thumb_url: poster.Poster,
photo_url: poster.Poster
}))
return answerInlineQuery(results)
})
bot.launch()