Reputation: 359
I am making a little app for telegram using CloudRail. This is my node.js server. The node.js sends message to a telegram user when it receives a POST request of kind "sendMessage". But I also want to be able to receive the responses that users sends. How do I listen to the responses the user makes?
var express = require('express');
var router = express.Router();
var http = require('http');
var fs = require('fs');
const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("pass");
const service = new cloudrail.services.Telegram(
null,
"botkey",
"webhook"
);
function sendMessage(user,message){
service.sendMessage(
user,
message,
(error, result) => {
if(error){ console.log("hubo un error");}
// Check for potential error and use the result
}
);
}
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.post("/",function(req,res,next){
service.parseReceivedMessages(
httpRequest: stream.Readable,
(error, result) => {
sendMessage("219148418","esta es mi respuesta");
// Check for potential error and use the result
}
)
if(req.method ==="POST" && req.body.kind != undefined && req.body.kind=="postMessage"){
var user_id = req.body.user_id;
var message = req.body.message;
sendMessage(user_id, message);
}
});
module.exports = router;
Upvotes: 0
Views: 89
Reputation: 26
The parseReceivedMessages receieves type Message which is a response from the user.
See the example: https://github.com/CloudRail/cloudrail-si-node-sdk/blob/master/examples/unified-messaging/index.js
Upvotes: 0