-
-
Save dotcypress/262ae2469c7b413407bc69c2f645c15e to your computer and use it in GitHub Desktop.
Telegram inline keyboard bug showcase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Composer, Markup } = require('micro-bot') | |
const fetch = require('node-fetch') | |
async function search (query, offset, limit) { | |
const apiUrl = `https://api.spotify.com/v1/search?type=track&limit=${limit}&offset=${offset}&q=${encodeURIComponent(query)}` | |
const response = await fetch(apiUrl) | |
const { tracks } = await response.json() | |
return tracks.items | |
} | |
const shortKeyboard = Markup.inlineKeyboard([ | |
Markup.callbackButton('Add', 'add'), , | |
Markup.switchToChatButton('Dummy', '😱') | |
]) | |
const longKeyboard = Markup.inlineKeyboard([ | |
Markup.callbackButton('Add', 'add'), | |
Markup.switchToChatButton('Dummy', '😱'), | |
Markup.switchToChatButton('Dummy', '🚨'), | |
Markup.switchToChatButton('Dummy', '🍗') | |
]) | |
const bot = new Composer() | |
bot.on('inline_query', async (ctx) => { | |
const offset = parseInt(ctx.inlineQuery.offset) || 0 | |
const tracks = await search(ctx.inlineQuery.query || '', offset, 30) | |
const results = tracks.map((track) => ({ | |
type: 'audio', | |
id: track.id, | |
title: track.name, | |
audio_url: track.preview_url, | |
reply_markup: shortKeyboard | |
}) | |
) | |
return ctx.answerInlineQuery(results, { next_offset: offset + 30}) | |
}) | |
bot.action('add', async (ctx) => ctx.editMessageReplyMarkup(longKeyboard)) | |
module.exports = bot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment