I have a Firebase Cloud Function that needs to do a post
to the Telegram API that sends a message to an user via a Telegram bot. When I send a message to the bot, I can see it hits my Cloud Function with the correct data, but when I do the post
in my Cloud Function to the Telegram API, I get the following error:
Error: getaddrinfo ENOTFOUND api.telegram.org api.telegram.org:443
I've tried to many code sets to post it all here and I've also tried the Telegram Bot API as well.
Here's my latest code (typescript) attempt I've tried:
import * as functions from 'firebase-functions';
import * as https from 'https';
export const telosbots = functions.https.onRequest((request, response) => {
let message = request.body.message;
console.log(`REQUEST INFO`, message);
let options: https.RequestOptions = {
host: 'https://api.telegram.org',
path: '/bot<bot_token_comes_here>/sendMessage',
method: 'POST',
headers: {
'content-type': 'application/json'
}
};
let req = https.request(options, resp => {
resp.setEncoding('utf8');
resp.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', e => {
console.log('ERROR: ' + e.message);
});
let body = JSON.stringify({ chat_id: message.chat.id, text: `Test` });
req.write(body);
req.end(`ok`);
});