From bf9353a5ccbfa7f38ed45d0f00694d30b2900745 Mon Sep 17 00:00:00 2001 From: Christopher Rose Date: Mon, 5 Aug 2019 20:56:31 +0530 Subject: [PATCH] Implement basic replies --- index.js | 3 +-- scripts/process.js | 11 +++++++++-- scripts/respond.js | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9e479cf..4c4236a 100644 --- a/index.js +++ b/index.js @@ -36,7 +36,6 @@ setInterval(()=>{ } // contents - Now work on response if(contents.result.length>0){ - //console.log(`Update:${JSON.stringify(contents.result)}`) // Ready to work on if(parameters.offset===null){ parameters.offset = contents.result[0].update_id + 1 @@ -47,7 +46,7 @@ setInterval(()=>{ parameters.offset = e.update_id + 1 } //console.log(e.update_id) - respond.call(e) + respond.call(base,e) }) diff --git a/scripts/process.js b/scripts/process.js index f386053..a7080e6 100644 --- a/scripts/process.js +++ b/scripts/process.js @@ -1,3 +1,10 @@ -module.exports.process = (updateObject)=>{ - return updateObject.message.text +// Obtain a sendMessage Object + +module.exports = (updateObject)=>{ + return { + "chat_id": updateObject.from.id, + "text":updateObject.text, + "reply_to_message_id": updateObject.message_id + } + //return JSON.stringify(updateObject) } \ No newline at end of file diff --git a/scripts/respond.js b/scripts/respond.js index b6f26ea..a21cc07 100644 --- a/scripts/respond.js +++ b/scripts/respond.js @@ -1,6 +1,19 @@ -module.exports.call = (updateObject)=>{ +// Send update object for processing and request to send reply + +const process = require('./process') +const request = require('request') + +module.exports.call = (base,updateObject)=>{ if('message' in updateObject){ - console.log(updateObject.message.text) - //console.log("New Message") + let responseObject = process(updateObject.message) + //console.log(process.process(updateObject.message)) + request.post({ + "url":`${base}sendMessage`, + "json":true, + "body":responseObject + },(err,res,body)=>{ + if(err) console.log(err) + if(body.ok) console.log("Successfully sent") + }) } } \ No newline at end of file