Skip to content

Instantly share code, notes, and snippets.

@iamnotstatic

iamnotstatic/app.js

Last active Nov 28, 2020
Embed
What would you like to do?
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot("YOUR_BOT_TOKEN", { polling: true });
const request = require('request');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
bot.onText(/\/movie (.+)/, (msg, match) => {
let movie = match[1];
let chatId = msg.chat.id;
request(`http://www.omdbapi.com/?apiKey=YOUROMDAPIKEY=&t=${movie}`, (error, response, body) => {
if (!error && response.statusCode == 200) {
bot.sendMessage(chatId, '_Looking for _' + movie + '...', { parse_mode: 'Markdown' })
.then((msg) => {
let res = JSON.parse(body);
bot.sendPhoto(chatId, res.Poster, { caption: 'Result:
\nTitle: ' + res.Title + '
\nYear: ' + res.Year + '
\nRated: ' + res.Rated + '
\nReleased: ' + res.Released + '
\nRuntime: ' + res.Runtime + '
\nGenre: ' + res.Genre + '
\nDirector: ' + res.Director + '
\nPlot: ' + res.Plot })
.catch((err) => {
if (err) {
bot.sendMessage(chatId, 'Bad request, Please check the title and try again');
}
})
})
}
})
})
app.listen(port, function () {
console.log(`Server is up on port ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment