How To Response To telegram bot Webhook Request? Same Request Are Coming Repeatedly

MaxySpark

I am trying to make a telegram bot(for learning purpose) with nodejs using official telegram bot api. I set a webhook to heroku. I am able to reply the request but after some time the same request come again after some time. Is it normal to get same request or I did not response to the coming request. when I call the getwebhookinfo method it shows pending_update_count but my code did response to all request coming from webhook. I use this to reply to the coming requests

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var config = require('./lib/config');
var request = require('request');
var port = process.env.PORT || 3000;
var reply_url = "https://api.telegram.org/bot"+config.bot_token;
app.use(bodyParser.json());
app.get('/',function(req,res) {
    res.send("Working");
request({
    url: "https://api.telegram.org/bot"+config.bot_token+'/getMe',
    json : true
}, (err,res,body)=>{
    console.log(body);
});
});
app.post('/'+config.bot_token , (req,res)=>{
    var body = req.body;
    console.log(body);
    console.log(body.message.entities);

    request.post((reply_url+'/sendMessage'),{form:{chat_id:body.message.chat.id,text:"POST REPLY SUCCESS",reply_to_message_id:body.message.message_id}});
});

app.listen(port, () =>
{
    console.log("Server is Started at - "+port);
});
Phagun Baya

try adding next in the callback function of the API function(req, res, next) and call next() function after you do res.status(201).send('Working").

Similar applies to other POST API ('/'+config.bot_token); in the success and error callback of /sendMessage API, call res.status().send() and then next();

Always call next() as a standard practice in working with express.js

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Telegram Bot: Wrong response from the webhook: 404 Bad Request

From Dev

how perform a request to the telegram Bot API while sending an answer to the webhook?

From Dev

How to Identify a Request is coming from same machine?

From Dev

How to use offset on Telegram bot API webHook

From Dev

How to test telegram bot webhook on local machine?

From Dev

How to set webhook for telegram bot in python?

From Dev

Use request_contact for KeyboardButton telegram Bot

From Dev

Telegram bot - importing contacts and request for number

From Dev

Node Telegram Bot API return Bad Request: there is no photo in the request

From Dev

Node Telegram Bot API return Bad Request: there is no photo in the request

From Dev

How to format a HTTP response to a HTTP request coming from a getJSON() jQuery call

From Dev

How to make a cURL request that produces the same response headers as Firefox

From Dev

Error 400 bad request while sending message with Telegram Bot

From Dev

(Telegram bot) JSON post request doesn't work

From Dev

Telegram Bot - Bad Request: wrong file identifier/HTTP URL specified

From Dev

How to Integrate webhook with paypal return request

From Dev

Can I use the same url for a webhook from more than one Telegram bot

From Dev

Is the response returned same as the request passed in Django?

From Dev

Restful - same request but difference response on different scenarios

From Dev

How to build the response for curl request?

From Dev

how to get response of http request

From Dev

Verifying request of Webhook

From Dev

Telegram bot API no JSON POST data on webhook

From Dev

Running request repeatedly with a timer in Android

From Dev

How to determine where a request is coming from in a REST api

From Dev

how can i check where the google font request is coming from?

From Dev

how can i check where the google font request is coming from?

From Dev

How to make Lambda function request coming from user's IP

From Dev

Alamofire request coming up nil

Related Related

  1. 1

    Telegram Bot: Wrong response from the webhook: 404 Bad Request

  2. 2

    how perform a request to the telegram Bot API while sending an answer to the webhook?

  3. 3

    How to Identify a Request is coming from same machine?

  4. 4

    How to use offset on Telegram bot API webHook

  5. 5

    How to test telegram bot webhook on local machine?

  6. 6

    How to set webhook for telegram bot in python?

  7. 7

    Use request_contact for KeyboardButton telegram Bot

  8. 8

    Telegram bot - importing contacts and request for number

  9. 9

    Node Telegram Bot API return Bad Request: there is no photo in the request

  10. 10

    Node Telegram Bot API return Bad Request: there is no photo in the request

  11. 11

    How to format a HTTP response to a HTTP request coming from a getJSON() jQuery call

  12. 12

    How to make a cURL request that produces the same response headers as Firefox

  13. 13

    Error 400 bad request while sending message with Telegram Bot

  14. 14

    (Telegram bot) JSON post request doesn't work

  15. 15

    Telegram Bot - Bad Request: wrong file identifier/HTTP URL specified

  16. 16

    How to Integrate webhook with paypal return request

  17. 17

    Can I use the same url for a webhook from more than one Telegram bot

  18. 18

    Is the response returned same as the request passed in Django?

  19. 19

    Restful - same request but difference response on different scenarios

  20. 20

    How to build the response for curl request?

  21. 21

    how to get response of http request

  22. 22

    Verifying request of Webhook

  23. 23

    Telegram bot API no JSON POST data on webhook

  24. 24

    Running request repeatedly with a timer in Android

  25. 25

    How to determine where a request is coming from in a REST api

  26. 26

    how can i check where the google font request is coming from?

  27. 27

    how can i check where the google font request is coming from?

  28. 28

    How to make Lambda function request coming from user's IP

  29. 29

    Alamofire request coming up nil

HotTag

Archive