-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Fix] Reviewed and Fix the remaining code
- Loading branch information
1 parent
cba9f11
commit a76e616
Showing
39 changed files
with
392 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.weather_api_key = process.env.WEATHER_SERVICE_API_KEY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
exports.verification_token = process.env.MESSENGER_BOT_VERIFICATION_TOKEN; | ||
exports.access_token = process.env.MESSENGER_BOT_ACESS_TOKEN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
node_env: process.env.NODE_ENV, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
module.exports = { | ||
database: require("./database"), | ||
common: require("./common"), | ||
request: require("./request") | ||
}; | ||
request: require("./request"), | ||
bot: require("./bot"), | ||
api_key: require("./api_key"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
MESSAGE:"MESSAGE", | ||
USER:"USER", | ||
}; | ||
MESSAGE: "MESSAGE", | ||
USER: "USER", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = { | ||
HTTP_CODES: require("./http_codes"), | ||
BOT: require("./bot"), | ||
CACHE_KEYS: require("./cache_keys"), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,66 @@ | ||
const {Message,User} = require("../repository"); | ||
const { Message, User } = require("../repository"); | ||
const mainService = require("../services"); | ||
const { | ||
bot: { verification_token }, | ||
} = require("../config"); | ||
|
||
/* | ||
A Preset Webhook for Bot to be fetch messages | ||
*/ | ||
async function event(request,response){ | ||
|
||
async function event(request, response) { | ||
const body = request.body; | ||
|
||
if (body.object === "page") { | ||
|
||
for (let entry of body.entry){ | ||
|
||
for (let entry of body.entry) { | ||
const event = entry.messaging[0]; | ||
response.status(200).send("EVENT_RECEIVED"); | ||
|
||
//Save any incoming messages | ||
new Message({ | ||
recipientId:event.recipient.id, | ||
senderId:event.sender.id, | ||
messageId:event.message.mid, | ||
message:event.message.text, | ||
timestamp:event.timestamp | ||
recipientId: event.recipient.id, | ||
senderId: event.sender.id, | ||
messageId: event.message.mid, | ||
message: event.message.text, | ||
timestamp: event.timestamp, | ||
}).create(); | ||
|
||
let user = await new User().getBySenderId(event.sender.id); | ||
if(!user){ | ||
if (!user) { | ||
user = await new User({ | ||
sender_id:event.sender.id | ||
sender_id: event.sender.id, | ||
}).create(); | ||
} | ||
|
||
//Sending User to Main Service | ||
await mainService(user,event.message.text,event.message.quick_reply?event.message.quick_reply.payload:null); | ||
|
||
await mainService( | ||
user, | ||
event.message.text, | ||
event.message.quick_reply ? event.message.quick_reply.payload : null | ||
); | ||
} | ||
|
||
} else { | ||
|
||
response.sendStatus(404); | ||
|
||
} | ||
|
||
} | ||
|
||
/* | ||
A Preset Webhook for Bot to be verified | ||
*/ | ||
function verification(request,response) { | ||
|
||
// Your verify token. Should be a random string. | ||
const VERIFY_TOKEN = process.env.MESSENGER_BOT_VERIFICATION_TOKEN; | ||
|
||
function verification(request, response) { | ||
let mode = request.query["hub.mode"]; | ||
let token = request.query["hub.verify_token"]; | ||
let challenge = request.query["hub.challenge"]; | ||
|
||
if (mode && token) { | ||
if (mode === "subscribe" && token === VERIFY_TOKEN) { | ||
if (mode === "subscribe" && token === verification_token) { | ||
response.status(200).send(challenge); | ||
} else { | ||
response.sendStatus(403); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = { | ||
event, | ||
verification | ||
}; | ||
verification, | ||
}; |
Oops, something went wrong.