2017-04-08 8 views
-1

バックエンドでNODEJSを使用して、IMDB NPM api.Followingからムービーデータを取得しています。私のserver.jsコードです。 autocompleteを使用するためのテレグラムボットでオートコンプリート検索ムービー名を実装する方法

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

あなたは[インラインモードを必要とするかもしれませ](https: //core.telegram.org/bots/inline)? – anatol

答えて

1

あなたは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 

Another example of inline bot

関連する問題