How to Design Movie Telegram Bot using Node.js ?
Last Updated :
02 Nov, 2020
Telegram bot API can be used to create a chatbot that returns the complete details of movies, web series, and Tv series by sending the name of the movie or series as a command. Telegram provides a bunch of API’s methods to perform different functions. The telegram bot can be used to know the complete details of the movie without going to other websites like the IMDb site, etc.
Prerequisites:
- Knowledge of Javascript and setting up a node environment.
- The latest version of Node (version > 10)
- The latest version of npm (version > 6)
Command to check if Node and npm are present in your system:
$ npm --v
6.14.5
$ node --version
v10.15.0
Creating Bot and Getting API Token:
- Open the telegram app and search for @BotFather.
- Click on the start button or send “/start”.
- Then send “/newbot” message to set up a name and a username.
- The BotFather will then give you an API token.
Getting Movie API Key:
- Go to the OMDB (open movie database ) website.
- Create an account as per the limit.
- You will receive your own API key.
Modules Installation:
Requests: To install this module type the below command in the terminal.
$ npm install --save requests
node-telegram-bot-api: Node.js module to interact with the official Telegram Bot API.
$ npm install node-telegram-bot-api
Filename: bot.js
javascript
// Requiring module
var reques = require('requests')
var TelegramBot = require('node-telegram-bot-api')
token = "YOUR-TELEGRAM_API-TOKEN"
movieapi = "YOUR-OMDB_API-TOKEN"
// Create a bot that uses 'polling'
// to fetch new updates
var bot = new TelegramBot(token, { polling: true });
bot.on("polling_error", (err) => console.log(err));
bot.onText(/\/movie (.+)/, function (msg, match) {
// The 'msg' is the received Message from
// user and 'match' is the result of
// execution above on the text content
// Getting the name of movie from the
// message sent to bot
var movie = match[1];
var chatId = msg.chat.id
reques('http://www.omdbapi.com/?t='
+ movie + '&apikey=movieapi',
function (error, response, body) {
if (!error && response.statusCode == 200) {
bot.sendMessage(chatId,
'_Looking for_ ' + movie + '...',
{ parse_mode: "Markdown" }).then(msg) {
res = JSON.parse(body)
bot.sendPhoto(chatId, res.Poster, {
caption: 'Result:\nTitle: '
+ res.Title + '\nGenre: '
+ res.Genre + '\nRated: '
+ res.Rated + ' \nReleased: '
+ res.Released
})
// Sending back response from the
// bot to the user
// Response has many other details,
// which can be used or sent as per
// requirement
}
}
})
})
Steps to run the program: Run bot.js file using the following command:
$ node bot.js
Now, Go to your bot and type /movie movie-name and see the results.
Output:

Similar Reads
How to Design a Weather Bot in Telegram using JavaScript ? Telegram bot can be used to know the complete weather details of any city, state, a country without going using another application. Telegram provides a bunch of API methods to perform different functions. You can use telegram bot API to create a Chatbot that returns weather-based information about
3 min read
How to build a simple Discord bot using Node.js ? Discord is an instant messaging application mostly used by developers and gamer communities. Many discord servers use bots to automate the task. Bots are programs that allow us to automate some tasks like messaging, maintaining our server, etc. Discord provides us with many built-in bots. Discord al
3 min read
How to Send Email using Mailgun API in Node.js ? Sending an email is an essential part of any project and it can be achieved by using Mailgun API. It is very popular for sending emails. Features of Mailgun: . It is easy to get started and easy to use.It is a widely used and popular module for sending emails.Mails can also be scheduled. Installati
2 min read
How to Send JSON Response using Node.js ? NodeJS is the runtime environment, which can execute the javascript code on any platform. It is widely used to create and run web application servers because of its salient features.During production, several times we need to send the resources or some type of information as a response, and javascri
5 min read
How to build Video Streaming Application using Node.js ? In this article, we are going to create a Video Streaming Application. A video streaming application is used to stream or play video, like a simple video player.Functionality: Play videoApproach: We are going to use express for this project, and create a server file app.js then we will create an HTM
4 min read