Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Enable twilio whatsapp template #1391

Merged
merged 14 commits into from
Sep 6, 2023
Merged
15 changes: 15 additions & 0 deletions apps/meteor/app/livechat/server/sendMessageBySMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ callbacks.add(
extraData = Object.assign({}, extraData, { location });
}

if (message.customFields && message.customFields.contentSid) {
const { contentSid } = message.customFields;
extraData = Object.assign({}, extraData, { contentSid });
}

if (message.customFields && message.customFields.contentVariables) {
const { contentVariables } = message.customFields;
extraData = Object.assign({}, extraData, { contentVariables });
}

if (message.customFields && message.customFields.messagingServiceSid) {
const { messagingServiceSid } = message.customFields;
extraData = Object.assign({}, extraData, { messagingServiceSid });
}

const SMSService = SMS.getService(settings.get('SMS_Service'));

if (!SMSService) {
Expand Down
27 changes: 24 additions & 3 deletions apps/meteor/app/sms/server/services/twilio.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ class Twilio {

client.messages
.create(currentItem)
.then(() => {})
.then((response) => {
logger.debug('Post message create: ', response);
})
.catch((err) => {
console.error(err);
});

logger.debug('Sent to Twillio:', currentItem.body);
logger.debug('Sent to Twillio: ', currentItem);
};

parse(data) {
Expand Down Expand Up @@ -104,6 +106,7 @@ class Twilio {
return returnData;
}

// eslint-disable-next-line complexity
send(fromNumber, toNumber, message, extraData) {
let body = message;

Expand Down Expand Up @@ -153,22 +156,40 @@ class Twilio {
body = TAPi18n.__('Location', { lng: defaultLanguage });
}

let contentSid;
let contentVariables;
let messagingServiceSid;
if (extraData && extraData.contentSid) {
contentSid = extraData.contentSid;
messagingServiceSid = extraData.messagingServiceSid;
}

if (extraData && extraData.contentVariables) {
contentVariables = JSON.stringify(extraData.contentVariables);
}

if (!messageQueue[toNumber]) {
messageQueue[toNumber] = [];
}

if (!body && !mediaUrl) {
if (!body && !mediaUrl && !contentSid) {
return;
}

messageQueue[toNumber].push({
to: toNumber,
// from: contentSid ? messagingServiceSid : fromNumber,
from: fromNumber,
body,
...(mediaUrl && { mediaUrl }),
...(persistentAction && { persistentAction }),
...(contentSid && { contentSid }),
ear-dev marked this conversation as resolved.
Show resolved Hide resolved
...(messagingServiceSid && { messagingServiceSid }),
...(contentVariables && { contentVariables }),
});

SystemLogger.debug('Twillio Payload:', messageQueue[toNumber]);

if (!messageQueueProcessor[toNumber]) {
messageQueueProcessor[toNumber] = setInterval(() => this.sendMessageToTwillio(toNumber), 1000);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
"tar-stream": "^1.6.2",
"tinykeys": "^1.4.0",
"turndown": "^7.1.1",
"twilio": "^3.76.1",
"twilio": "^4.14.0",
"twit": "^2.2.11",
"ua-parser-js": "^1.0.2",
"underscore": "^1.13.4",
Expand Down
72 changes: 28 additions & 44 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5390,7 +5390,7 @@ __metadata:
tinykeys: ^1.4.0
ts-node: ^10.8.1
turndown: ^7.1.1
twilio: ^3.76.1
twilio: ^4.14.0
twit: ^2.2.11
typescript: ~4.5.5
ua-parser-js: ^1.0.2
Expand Down Expand Up @@ -14531,13 +14531,20 @@ __metadata:
languageName: node
linkType: hard

"dayjs@npm:^1.10.4, dayjs@npm:^1.8.29":
"dayjs@npm:^1.10.4":
version: 1.11.0
resolution: "dayjs@npm:1.11.0"
checksum: 2d36f6d71345114cdcd89147adf9e05b4f8fe81684e08c8bf1f86b140aa0b86ecc3cae661a9348d96feb7fbefd03e1bc3697303688e95209670abcb36b4ece15
languageName: node
linkType: hard

"dayjs@npm:^1.11.9":
version: 1.11.9
resolution: "dayjs@npm:1.11.9"
checksum: a4844d83dc87f921348bb9b1b93af851c51e6f71fa259604809cfe1b49d1230e6b0212dab44d1cb01994c096ad3a77ea1cf18fa55154da6efcc9d3610526ac38
languageName: node
linkType: hard

"dayjs@npm:~1.8.24, dayjs@npm:~1.8.25":
version: 1.8.36
resolution: "dayjs@npm:1.8.36"
Expand Down Expand Up @@ -22425,7 +22432,7 @@ __metadata:
languageName: node
linkType: hard

"jsonwebtoken@npm:^8.1.0, jsonwebtoken@npm:^8.5.1":
"jsonwebtoken@npm:^8.1.0":
version: 8.5.1
resolution: "jsonwebtoken@npm:8.5.1"
dependencies:
Expand All @@ -22443,6 +22450,18 @@ __metadata:
languageName: node
linkType: hard

"jsonwebtoken@npm:^9.0.0":
version: 9.0.1
resolution: "jsonwebtoken@npm:9.0.1"
dependencies:
jws: ^3.2.2
lodash: ^4.17.21
ms: ^2.1.1
semver: ^7.3.8
checksum: 0eafe268896f4e8f9ab1f0f20e8c645721b7a9cddc41c0aba1e58da5c34564e8c9990817c1a5b646d795bcbb1339350826fe57c4569b5379ba9eea4a9aa5bbd0
languageName: node
linkType: hard

"jsprim@npm:^1.2.2":
version: 1.4.2
resolution: "jsprim@npm:1.4.2"
Expand Down Expand Up @@ -27262,13 +27281,6 @@ __metadata:
languageName: node
linkType: hard

"pop-iterate@npm:^1.0.1":
version: 1.0.1
resolution: "pop-iterate@npm:1.0.1"
checksum: 3147476c57bee79a0f07d111d7c8564bf7153cb15614ad49421497f1976825b89746af7a2581a136e8284001a4d5b9cbf2b1d4ac1ca540b089f9bf582ecddb14
languageName: node
linkType: hard

"portfinder@npm:^1.0.26":
version: 1.0.28
resolution: "portfinder@npm:1.0.28"
Expand Down Expand Up @@ -28576,17 +28588,6 @@ __metadata:
languageName: node
linkType: hard

"q@npm:2.0.x":
version: 2.0.3
resolution: "q@npm:2.0.3"
dependencies:
asap: ^2.0.0
pop-iterate: ^1.0.1
weak-map: ^1.0.5
checksum: ad3c925b242d06bd97c8bc7d57d5c6506bcae876f9172cffea7eacafe93a4f434f06f0eb6f87b59028f7b03dd15ed7fe7c6be8e3ab43173b584d8d40cb3a335d
languageName: node
linkType: hard

"q@npm:^1.1.2":
version: 1.5.1
resolution: "q@npm:1.5.1"
Expand Down Expand Up @@ -30265,13 +30266,6 @@ __metadata:
languageName: unknown
linkType: soft

"rootpath@npm:^0.1.2":
version: 0.1.2
resolution: "rootpath@npm:0.1.2"
checksum: e39fad0912f5757c087e1b9c0a66278bb9cbe5ffbacfb1960f75a4feddf16fe837319a5764abdb73839ef0e6ea8ef155b98eb383b951b25b279c153c50cd13f0
languageName: node
linkType: hard

"rsvp@npm:^4.8.4":
version: 4.8.5
resolution: "rsvp@npm:4.8.5"
Expand Down Expand Up @@ -33695,22 +33689,19 @@ __metadata:
languageName: node
linkType: hard

"twilio@npm:^3.76.1":
version: 3.76.1
resolution: "twilio@npm:3.76.1"
"twilio@npm:^4.14.0":
version: 4.14.1
resolution: "twilio@npm:4.14.1"
dependencies:
axios: ^0.26.1
dayjs: ^1.8.29
dayjs: ^1.11.9
https-proxy-agent: ^5.0.0
jsonwebtoken: ^8.5.1
lodash: ^4.17.21
q: 2.0.x
jsonwebtoken: ^9.0.0
qs: ^6.9.4
rootpath: ^0.1.2
scmp: ^2.1.0
url-parse: ^1.5.9
xmlbuilder: ^13.0.2
checksum: ab79962552412f5f61c479369374ace200518c00189314a59f030375b3e27e83cbd49f4287c09eb11aa11c728769ca7bc009b54454ed9c59570cf6c0aa468a84
checksum: 0d4d3fd82dd16d11d1201e0914ed9ee11cf5dc996fd136c709511693fa7138f5e8fe55d213f5f51482fa45292f555388cb2765ae4403e5527023da0dd6a4ea3d
languageName: node
linkType: hard

Expand Down Expand Up @@ -34894,13 +34885,6 @@ __metadata:
languageName: node
linkType: hard

"weak-map@npm:^1.0.5":
version: 1.0.8
resolution: "weak-map@npm:1.0.8"
checksum: ce030b3c6b1a461bda6eac88b3b3be57245ce26330c6ddb98d821d85c0636117ca94693ef8292407066fd367740ec6a1ef6cd9027111453d7ced43f4f78b327a
languageName: node
linkType: hard

"web-namespaces@npm:^1.0.0":
version: 1.1.4
resolution: "web-namespaces@npm:1.1.4"
Expand Down
Loading