forked from telegraf/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inline-bot.js
33 lines (29 loc) · 971 Bytes
/
inline-bot.js
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
30
31
32
33
const Telegraf = require('telegraf')
const Markup = require('telegraf/markup')
const fetch = require('node-fetch')
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.on('inline_query', async ({ inlineQuery, answerInlineQuery }) => {
const apiUrl = `http://recipepuppy.com/api/?q=${inlineQuery.query}`
const response = await fetch(apiUrl)
const { results } = await response.json()
const recipes = results
.filter(({ thumbnail }) => thumbnail)
.map(({ title, href, thumbnail }) => ({
type: 'article',
id: thumbnail,
title: title,
description: title,
thumb_url: thumbnail,
input_message_content: {
message_text: title
},
reply_markup: Markup.inlineKeyboard([
Markup.urlButton('Go to recipe', href)
])
}))
return answerInlineQuery(recipes)
})
bot.on('chosen_inline_result', ({ chosenInlineResult }) => {
console.log('chosen inline result', chosenInlineResult)
})
bot.launch()