| @@ -0,0 +1,52 @@ | |||||
| { | |||||
| "routes": [ | |||||
| { | |||||
| "method": "GET", | |||||
| "path": "/bots", | |||||
| "handler": "bot.find", | |||||
| "config": { | |||||
| "policies": [] | |||||
| } | |||||
| }, | |||||
| { | |||||
| "method": "GET", | |||||
| "path": "/bots/count", | |||||
| "handler": "bot.count", | |||||
| "config": { | |||||
| "policies": [] | |||||
| } | |||||
| }, | |||||
| { | |||||
| "method": "GET", | |||||
| "path": "/bots/:id", | |||||
| "handler": "bot.findOne", | |||||
| "config": { | |||||
| "policies": [] | |||||
| } | |||||
| }, | |||||
| { | |||||
| "method": "POST", | |||||
| "path": "/bots", | |||||
| "handler": "bot.create", | |||||
| "config": { | |||||
| "policies": [] | |||||
| } | |||||
| }, | |||||
| { | |||||
| "method": "PUT", | |||||
| "path": "/bots/:id", | |||||
| "handler": "bot.update", | |||||
| "config": { | |||||
| "policies": [] | |||||
| } | |||||
| }, | |||||
| { | |||||
| "method": "DELETE", | |||||
| "path": "/bots/:id", | |||||
| "handler": "bot.delete", | |||||
| "config": { | |||||
| "policies": [] | |||||
| } | |||||
| } | |||||
| ] | |||||
| } | |||||
| @@ -0,0 +1,8 @@ | |||||
| 'use strict'; | |||||
| /** | |||||
| * Read the documentation (https://strapi.io/documentation/developer-docs/latest/concepts/controllers.html#core-controllers) | |||||
| * to customize this controller | |||||
| */ | |||||
| module.exports = {}; | |||||
| @@ -0,0 +1,8 @@ | |||||
| 'use strict'; | |||||
| /** | |||||
| * Read the documentation (https://strapi.io/documentation/developer-docs/latest/concepts/models.html#lifecycle-hooks) | |||||
| * to customize this model | |||||
| */ | |||||
| module.exports = {}; | |||||
| @@ -0,0 +1,49 @@ | |||||
| { | |||||
| "kind": "collectionType", | |||||
| "collectionName": "bots", | |||||
| "info": { | |||||
| "name": "Bot", | |||||
| "description": "" | |||||
| }, | |||||
| "options": { | |||||
| "increments": true, | |||||
| "timestamps": true, | |||||
| "draftAndPublish": true | |||||
| }, | |||||
| "attributes": { | |||||
| "conditions": { | |||||
| "type": "enumeration", | |||||
| "enum": [ | |||||
| "time_based", | |||||
| "query_based" | |||||
| ] | |||||
| }, | |||||
| "trigger": { | |||||
| "type": "string" | |||||
| }, | |||||
| "start_date": { | |||||
| "type": "datetime" | |||||
| }, | |||||
| "end_date": { | |||||
| "type": "datetime" | |||||
| }, | |||||
| "periodic": { | |||||
| "type": "boolean" | |||||
| }, | |||||
| "message_template_key": { | |||||
| "model": "message-template", | |||||
| "via": "bot" | |||||
| }, | |||||
| "template_query": { | |||||
| "type": "json" | |||||
| }, | |||||
| "apply_to": { | |||||
| "collection": "chats", | |||||
| "via": "bots", | |||||
| "dominant": true | |||||
| }, | |||||
| "name": { | |||||
| "type": "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,8 @@ | |||||
| 'use strict'; | |||||
| /** | |||||
| * Read the documentation (https://strapi.io/documentation/developer-docs/latest/concepts/services.html#core-services) | |||||
| * to customize this service | |||||
| */ | |||||
| module.exports = {}; | |||||
| @@ -28,6 +28,13 @@ | |||||
| }, | }, | ||||
| "timestamp": { | "timestamp": { | ||||
| "type": "datetime" | "type": "datetime" | ||||
| }, | |||||
| "last_sessionId": { | |||||
| "type": "string" | |||||
| }, | |||||
| "bots": { | |||||
| "via": "apply_to", | |||||
| "collection": "bot" | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -27,6 +27,10 @@ | |||||
| "message": { | "message": { | ||||
| "via": "template_key", | "via": "template_key", | ||||
| "model": "message" | "model": "message" | ||||
| }, | |||||
| "bot": { | |||||
| "via": "message_template_key", | |||||
| "model": "bot" | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -41,6 +41,7 @@ module.exports = { | |||||
| os_version: data["DATA"].phone.os_version, | os_version: data["DATA"].phone.os_version, | ||||
| phonenumber: data["DATA"].wid.user, | phonenumber: data["DATA"].wid.user, | ||||
| session_data: data["DATA"].sessionData, | session_data: data["DATA"].sessionData, | ||||
| sessionId: data["DATA"].wid._serialized, | |||||
| } | } | ||||
| ); | ); | ||||
| } else { | } else { | ||||
| @@ -53,6 +54,7 @@ module.exports = { | |||||
| os_version: data["DATA"].phone.os_version, | os_version: data["DATA"].phone.os_version, | ||||
| phonenumber: data["DATA"].wid.user, | phonenumber: data["DATA"].wid.user, | ||||
| session_data: data["DATA"].sessionData, | session_data: data["DATA"].sessionData, | ||||
| sessionId: data["DATA"].wid._serialized, | |||||
| }); | }); | ||||
| // console.log(entry); | // console.log(entry); | ||||
| } | } | ||||
| @@ -32,6 +32,9 @@ | |||||
| "phonenumber": { | "phonenumber": { | ||||
| "type": "string", | "type": "string", | ||||
| "required": true | "required": true | ||||
| }, | |||||
| "sessionId": { | |||||
| "type": "string" | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -8,6 +8,7 @@ const refreshChat = async function (client, sessionsId) { | |||||
| if (client && sessionsId) { | if (client && sessionsId) { | ||||
| var chatId; | var chatId; | ||||
| var result = await messageModel.getAllChats(client); | var result = await messageModel.getAllChats(client); | ||||
| // console.log(result["DATA"]); | |||||
| if (result["STATUS"] == 1) { | if (result["STATUS"] == 1) { | ||||
| for (var i = 0; i < result["DATA"].length; i++) { | for (var i = 0; i < result["DATA"].length; i++) { | ||||
| var chatsExist = await strapi.api["chats"].services[ | var chatsExist = await strapi.api["chats"].services[ | ||||
| @@ -17,22 +18,34 @@ const refreshChat = async function (client, sessionsId) { | |||||
| phoneNumber: result["DATA"][i]["id"].user, | phoneNumber: result["DATA"][i]["id"].user, | ||||
| }); | }); | ||||
| if (!chatsExist) { | if (!chatsExist) { | ||||
| await strapi.query("chats").create({ | |||||
| session_key: sessionsId, | |||||
| name: result["DATA"][i]["name"], | |||||
| unreadCount: result["DATA"][i]["unreadCount"], | |||||
| timestamp: moment | |||||
| .unix(result["DATA"][i]["timestamp"]) | |||||
| .toDate(), | |||||
| chatId: result["DATA"][i]["id"], | |||||
| phoneNumber: result["DATA"][i]["id"].user, | |||||
| }); | |||||
| //check again with last active session | |||||
| chatsExist = await strapi.api["chats"].services[ | chatsExist = await strapi.api["chats"].services[ | ||||
| "chats" | "chats" | ||||
| ].findOne({ | ].findOne({ | ||||
| session_key: sessionsId, | |||||
| last_sessionId: client.info.me._serialized, | |||||
| phoneNumber: result["DATA"][i]["id"].user, | phoneNumber: result["DATA"][i]["id"].user, | ||||
| }); | }); | ||||
| if (!chatsExist) { | |||||
| await strapi.query("chats").create({ | |||||
| session_key: sessionsId, | |||||
| name: result["DATA"][i]["name"], | |||||
| unreadCount: result["DATA"][i]["unreadCount"], | |||||
| timestamp: moment | |||||
| .unix(result["DATA"][i]["timestamp"]) | |||||
| .toDate(), | |||||
| chatId: result["DATA"][i]["id"], | |||||
| phoneNumber: result["DATA"][i]["id"].user, | |||||
| last_sessionId: client.info.me._serialized, | |||||
| }); | |||||
| } else { | |||||
| let id = chatsExist.id; | |||||
| await strapi.query("chats").update( | |||||
| { id }, | |||||
| { | |||||
| session_key: sessionsId, | |||||
| } | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| var messages = await messageModel.getMessagebyId( | var messages = await messageModel.getMessagebyId( | ||||
| client, | client, | ||||
| @@ -21,6 +21,14 @@ const refreshMessage = async function (message, chat) { | |||||
| timestamp: moment.unix(message["timestamp"]).toDate(), | timestamp: moment.unix(message["timestamp"]).toDate(), | ||||
| }); | }); | ||||
| // console.log("message added"); | // console.log("message added"); | ||||
| } else { | |||||
| let id = Exist.id; | |||||
| await strapi.query("message").update( | |||||
| { id }, | |||||
| { | |||||
| chat_key: chat.id, | |||||
| } | |||||
| ); | |||||
| } | } | ||||
| }; | }; | ||||