# Telegram node.js AWS Lambda 502 error

**URL:** <https://forum.serverless.com/t/telegram-node-js-aws-lambda-502-error/7941>\
**Category:** Serverless Framework\
**Created:** [April 9, 2019, 2:32pm UTC](https://forum.serverless.com/t/telegram-node-js-aws-lambda-502-error/7941 "2019-04-09T14:32:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![time2coffee](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@time2coffee](https://forum.serverless.com/u/time2coffee)\
**Post date:** [April 9, 2019, 2:32pm UTC](https://forum.serverless.com/t/telegram-node-js-aws-lambda-502-error/7941/1 "2019-04-09T14:32:25Z")

</div>

I have succeded with my first node app on Lambda using serverless. It works great when I open it from http endpoint after executing serverless deploy -v!

My target is to get my node.js telegram bot running on lambda. When I insert bot logic into export.module.hello , deploy in console, set telegram webhook, get no response after run /start command in my bot and then check same http endpoint webhook by opening [api.telegram.org/botXXX/getWebhookinfo](http://api.telegram.org/botXXX/getWebhookinfo) - what I get is “Wrong response from the webhook: 502 Bad Gateway”

this is my handler.js code:

```
'use strict';

module.exports.hello = async (context, cb) => {
  const TelegramBot = require('node-telegram-bot-api');

  const token = "token";
  const bot = new TelegramBot(token);
  const chatId = context.body.message.chat.id;

  const out = bot.sendMessage(chatId, 'Hello World!');
  return cb(null, out);
};

```

and this is serverless.yml (functions part of it)

```
functions:
  hello:
    handler: handler.hello
    events:
      - http: POST hello

```

I am comfortably running node.js code for telegram from a localhost, but seems cannot wrap this code inside lambda function… Otherwise what can be a problem causing 502 error, when I check getWebhookinfo?  
Any advice will be much appreciated!

---

<div class="post-metadata">

**Author:** ![moro](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/moro/32/4303_2.png) [@moro](https://forum.serverless.com/u/moro)\
**Post date:** [April 13, 2019, 7:00pm UTC](https://forum.serverless.com/t/telegram-node-js-aws-lambda-502-error/7941/2 "2019-04-13T19:00:14Z")

</div>

Hi, if I’m not mistaken `bot.sendMessage` returns a promise, you use an async function, so I think you don’t need to use `cb` + you need to add `await` + return a correct message.

```auto
  const TelegramBot = require('node-telegram-bot-api');

  const { TOKEN } = process.env;
  const bot = new TelegramBot(TOKEN); 

module.exports.hello = async (event) => {
  const chatId = event.body.message.chat.id;
  const result = await bot.sendMessage(chatId, 'Hello World!');

  return { statusCode: 200, body : JSON.stringify(result) };
};

```

p.s. have you tried to call this url using postman or something similar?
