From 82bcaa6a723eaa4161efed37133c1d967a3cdf33 Mon Sep 17 00:00:00 2001 From: MCSH Date: Sat, 27 May 2017 22:08:16 +0430 Subject: [PATCH 1/2] Added game example --- examples/game/game.html | 138 ++++++++++++++++++++++++++++++++++++++++ examples/game/game.js | 39 ++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 examples/game/game.html create mode 100644 examples/game/game.js diff --git a/examples/game/game.html b/examples/game/game.html new file mode 100644 index 00000000..5ce46189 --- /dev/null +++ b/examples/game/game.html @@ -0,0 +1,138 @@ + + + + + + + + + +
+ +

Use the ACCELERATE button to stay in the air

+

How long can you stay alive?

+ + diff --git a/examples/game/game.js b/examples/game/game.js new file mode 100644 index 00000000..5e10bff6 --- /dev/null +++ b/examples/game/game.js @@ -0,0 +1,39 @@ +/** + * This example demonstrates using polling. + * It also demonstrates how you would process and send messages. + */ + + +const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN'; +const TelegramBot = require('../..'); +const request = require('request'); +const options = { + polling: true +}; +const bot = new TelegramBot(TOKEN, options); +const express = require('express') +const app = express() +const url = "http://example.com"; +const gameLink = url + '/'; +const gameName = "game"; +const port = process.env.PORT || 8080; +app.set('view engine', 'ejs') + +// Matches /start +bot.onText(/\/start/, function onPhotoText(msg) { + bot.sendGame(msg.chat.id, gameName); +}); + +// Handle callback queries +bot.on('callback_query', function onCallbackQuery(callbackQuery) { + const msg = callbackQuery.message; + bot.answerCallbackQuery(msg.id, gameLink, true, {url: gameLink}); +}); + +app.get('/', function(req, res){ + res.render('game.html'); +}); + +app.listen(port, function(){ + console.log("Listening on port " + port); +}); From 5e8769d018d8ebdb39e24b328ba63aa5d9a44259 Mon Sep 17 00:00:00 2001 From: Sajjad Heydari Date: Thu, 26 Oct 2017 16:34:06 +0330 Subject: [PATCH 2/2] Fixed 418 --- examples/game/game.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/game/game.js b/examples/game/game.js index 2180863a..f8967f13 100644 --- a/examples/game/game.js +++ b/examples/game/game.js @@ -39,7 +39,7 @@ bot.onText(/\/start/, function onPhotoText(msg) { // Handle callback queries bot.on('callback_query', function onCallbackQuery(callbackQuery) { - bot.answerCallbackQuery(callbackQuery.id, url, true, { url }); + bot.answerCallbackQuery({url: url, callback_query_id: callbackQuery.id}); }); // Render the HTML game