我在后端使用NODEJS从IMDB NPM api获取电影数据。以下是我的server.js代码。
server.js
var token ="token";
var telegramBot= require('node-telegram-bot-api');
var bot= new telegramBot(token,{polling:true});
var express= require('express');
var imdb = require('imdb-api');
var app =express();
app.listen(8080,function(){
console.log("listening on 8080")
})
bot.onText(/Moviename/, function(msg, match) {
data = msg.text;
imdb.get(msg.text, function(err, movieList){
console.log(movieList);
bot.sendMessage(msg.chat.id,movieList);
//how i send data to bot when I type on keyboard
});
});
答案 0 :(得分:1)
要使用autocomplete
,您可能需要阅读inline mode documentation
工作示例:
// Docs: https://github.com/telegraf/micro-bot
const { Composer } = require('micro-bot')
const imdb = require('imdb-api')
const bot = new Composer()
bot.on('inline_query', async (ctx) => {
const movies = await imdb.get(ctx.inlineQuery.query)
const results = movies.map((movie) => ({
type: 'article',
id: movie.id,
title: movie.title,
photo_url: movie.poster
}))
return ctx.answerInlineQuery(results)
})
module.exports = bot