@tiledesk/tiledesk-whatsapp-connector 0.1.28 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +55 -40
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -898,13 +898,20 @@ router.post("/newtest", async (req, res) => {
|
|
|
898
898
|
|
|
899
899
|
//let short_uid = getRandomName();
|
|
900
900
|
let short_uid = uuidv4().substring(0, 8)
|
|
901
|
-
let
|
|
901
|
+
let key = "bottest:" + short_uid;
|
|
902
902
|
|
|
903
|
-
await redis_client.
|
|
904
|
-
const value = await redis_client.
|
|
905
|
-
console.log("get --> value: ", value)
|
|
903
|
+
await redis_client.set(key, JSON.stringify(info));
|
|
904
|
+
//const value = await redis_client.get(key)
|
|
905
|
+
//console.log("get --> value: ", value)
|
|
906
|
+
redis_client.get(key, (err, value) => {
|
|
907
|
+
if (err) {
|
|
908
|
+
console.log("get err: ", err)
|
|
909
|
+
} else {
|
|
910
|
+
console.log("get value: ", value)
|
|
911
|
+
}
|
|
912
|
+
})
|
|
906
913
|
/*
|
|
907
|
-
const value = await redis_client.json.get(
|
|
914
|
+
const value = await redis_client.json.get(key, {
|
|
908
915
|
// JSON Path: .node = the element called 'node' at root level.
|
|
909
916
|
path: '.nodell',
|
|
910
917
|
});
|
|
@@ -924,11 +931,23 @@ router.post("/testitout/:project_id", async (req, res) => {
|
|
|
924
931
|
|
|
925
932
|
let whatsappContact = req.body.entry[0].changes[0].value.contacts[0];
|
|
926
933
|
|
|
927
|
-
let
|
|
928
|
-
console.log("(testitout) key: ",
|
|
934
|
+
let key = "bottest:" + whatsappChannelMessage.text.body.substring(3);
|
|
935
|
+
console.log("(testitout) key: ", key);
|
|
929
936
|
|
|
937
|
+
/*
|
|
930
938
|
const info = await redis_client.json.get(REDIS_KEY);
|
|
931
939
|
console.log("(testitout) info: ", info);
|
|
940
|
+
*/
|
|
941
|
+
let test_info;
|
|
942
|
+
redis_client.get(key, (err, value) => {
|
|
943
|
+
if (err) {
|
|
944
|
+
console.log("No info found on redis. Exit..");
|
|
945
|
+
res.sendStatus(200);
|
|
946
|
+
} else {
|
|
947
|
+
test_info = JSON.parse(value)
|
|
948
|
+
console.log("test_info: ", test_info)
|
|
949
|
+
}
|
|
950
|
+
})
|
|
932
951
|
|
|
933
952
|
let message_info = {
|
|
934
953
|
channel: "whatsapp",
|
|
@@ -960,7 +979,7 @@ router.post("/testitout/:project_id", async (req, res) => {
|
|
|
960
979
|
console.log("(testitout) tiledeskJsonMessage: ", tiledeskJsonMessage)
|
|
961
980
|
|
|
962
981
|
const tdChannel = new TiledeskChannel({ settings: settings, API_URL: API_URL })
|
|
963
|
-
const response = await tdChannel.sendAndAddBot(tiledeskJsonMessage, message_info,
|
|
982
|
+
const response = await tdChannel.sendAndAddBot(tiledeskJsonMessage, message_info, test_info.bot_id)
|
|
964
983
|
console.log("testitout --> send response: ", response)
|
|
965
984
|
|
|
966
985
|
res.status(200).send("testitout")
|
|
@@ -972,7 +991,7 @@ router.post("/testitout/:project_id", async (req, res) => {
|
|
|
972
991
|
// *****************************
|
|
973
992
|
|
|
974
993
|
async function startApp(settings, callback) {
|
|
975
|
-
console.log("Starting Whatsapp App");
|
|
994
|
+
console.log("(whatsapp) Starting Whatsapp App");
|
|
976
995
|
|
|
977
996
|
if (!settings.MONGODB_URL) {
|
|
978
997
|
throw new Error("settings.MONGODB_URL is mandatory");
|
|
@@ -982,49 +1001,37 @@ async function startApp(settings, callback) {
|
|
|
982
1001
|
throw new Error("settings.API_URL is mandatory");
|
|
983
1002
|
} else {
|
|
984
1003
|
API_URL = settings.API_URL;
|
|
985
|
-
console.log("API_URL: ", API_URL);
|
|
1004
|
+
console.log("(whatsapp) API_URL: ", API_URL);
|
|
986
1005
|
}
|
|
987
1006
|
|
|
988
1007
|
if (!settings.BASE_URL) {
|
|
989
1008
|
throw new Error("settings.BASE_URL is mandatory");
|
|
990
1009
|
} else {
|
|
991
1010
|
BASE_URL = settings.BASE_URL;
|
|
992
|
-
console.log("BASE_URL: ", BASE_URL);
|
|
1011
|
+
console.log("(whatsapp) BASE_URL: ", BASE_URL);
|
|
993
1012
|
}
|
|
994
1013
|
|
|
995
1014
|
if (!settings.GRAPH_URL) {
|
|
996
1015
|
throw new Error("settings.GRAPH_URL is mandatory");
|
|
997
1016
|
} else {
|
|
998
1017
|
GRAPH_URL = settings.GRAPH_URL;
|
|
999
|
-
console.log("GRAPH_URL: ", GRAPH_URL);
|
|
1018
|
+
console.log("(whatsapp) GRAPH_URL: ", GRAPH_URL);
|
|
1000
1019
|
}
|
|
1001
1020
|
|
|
1002
1021
|
if (!settings.APPS_API_URL) {
|
|
1003
1022
|
throw new Error("settings.APPS_API_URL is mandatory");
|
|
1004
1023
|
} else {
|
|
1005
1024
|
APPS_API_URL = settings.APPS_API_URL;
|
|
1006
|
-
console.log("APPS_API_URL: ", APPS_API_URL);
|
|
1025
|
+
console.log("(whatsapp) APPS_API_URL: ", APPS_API_URL);
|
|
1007
1026
|
}
|
|
1008
1027
|
|
|
1009
|
-
if (
|
|
1010
|
-
throw new Error("!settings.REDIS_HOST is mandatory");
|
|
1011
|
-
} else {
|
|
1028
|
+
if (settings.REDIS_HOST && settings.REDIS_PORT && settings.REDIS_PASSWORD) {
|
|
1012
1029
|
REDIS_HOST = settings.REDIS_HOST;
|
|
1013
|
-
console.log("REDIS_HOST: ", REDIS_HOST);
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
if (!settings.REDIS_PORT) {
|
|
1017
|
-
throw new Error("!settings.REDIS_PORT is mandatory");
|
|
1018
|
-
} else {
|
|
1019
1030
|
REDIS_PORT = settings.REDIS_PORT;
|
|
1020
|
-
console.log("REDIS_PORT: ", REDIS_PORT);
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
if (!settings.REDIS_PASSWORD) {
|
|
1024
|
-
throw new Error("!settings.REDIS_PASSWORD is mandatory");
|
|
1025
|
-
} else {
|
|
1026
1031
|
REDIS_PASSWORD = settings.REDIS_PASSWORD;
|
|
1027
|
-
|
|
1032
|
+
connectRedis();
|
|
1033
|
+
} else {
|
|
1034
|
+
console.log("(whatsapp) Missing redis parameters --> Test it out on WhatsApp disabled");
|
|
1028
1035
|
}
|
|
1029
1036
|
|
|
1030
1037
|
if (settings.log) {
|
|
@@ -1037,8 +1044,24 @@ async function startApp(settings, callback) {
|
|
|
1037
1044
|
password: REDIS_PASSWORD
|
|
1038
1045
|
});
|
|
1039
1046
|
|
|
1047
|
+
db.connect(settings.MONGODB_URL, () => {
|
|
1048
|
+
console.log("(whatsapp) KVBaseMongo successfully connected.");
|
|
1049
|
+
|
|
1050
|
+
if (callback) {
|
|
1051
|
+
callback();
|
|
1052
|
+
}
|
|
1053
|
+
})
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
function connectRedis() {
|
|
1057
|
+
redis_client = redis.createClient({
|
|
1058
|
+
host: REDIS_HOST,
|
|
1059
|
+
port: REDIS_PORT,
|
|
1060
|
+
password: REDIS_PASSWORD
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1040
1063
|
redis_client.on('error', err => {
|
|
1041
|
-
console.log('Error ' + err);
|
|
1064
|
+
console.log('(whatsapp) Connect Redis Error ' + err);
|
|
1042
1065
|
})
|
|
1043
1066
|
/*
|
|
1044
1067
|
redis_client.on('connect', () => {
|
|
@@ -1046,22 +1069,14 @@ async function startApp(settings, callback) {
|
|
|
1046
1069
|
});
|
|
1047
1070
|
*/
|
|
1048
1071
|
redis_client.on('ready', () => {
|
|
1049
|
-
console.log("Redis ready")
|
|
1072
|
+
console.log("(whatsapp) Redis ready!")
|
|
1050
1073
|
})
|
|
1051
1074
|
//await redis_client.connect(); // only for v4
|
|
1052
|
-
|
|
1053
1075
|
|
|
1054
|
-
db.connect(settings.MONGODB_URL, () => {
|
|
1055
|
-
console.log("KVBaseMongo successfully connected.");
|
|
1056
|
-
|
|
1057
|
-
if (callback) {
|
|
1058
|
-
callback();
|
|
1059
|
-
}
|
|
1060
|
-
})
|
|
1061
1076
|
}
|
|
1062
1077
|
|
|
1063
1078
|
function readHTMLFile(templateName, callback) {
|
|
1064
|
-
console.log("Reading file: ", templateName)
|
|
1079
|
+
//console.log("Reading file: ", templateName)
|
|
1065
1080
|
fs.readFile(__dirname + '/template' + templateName, { encoding: 'utf-8' },
|
|
1066
1081
|
function(err, html) {
|
|
1067
1082
|
if (err) {
|