gupshup-whatsapp-sdk
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -15,3 +15,3 @@ "use strict"; | ||
defaultHeaders: { | ||
// "apikey": config.APP_KEY, | ||
"apikey": config.APP_KEY, | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
@@ -86,3 +86,24 @@ "Accept": "application/json", | ||
sendReplyButtons(source, destination, sourceName, payload, button) { | ||
let type = Object.assign(Object.assign({ "type": "quick_reply" }, payload), button); | ||
let resultContent = ''; | ||
let resultOptions = ''; | ||
let entriesContent = Object.entries(payload.content); | ||
entriesContent.map(([key, val], i, arr) => { | ||
let message = resultContent; | ||
if (arr.length - 1 === i) { | ||
resultContent = message.concat(`"${key}": "${val}" `); | ||
} | ||
else { | ||
resultContent = message.concat(`"${key}": "${val}", `); | ||
} | ||
}); | ||
let entriesOptions = button.options; | ||
entriesOptions.map((e, i, arr) => { | ||
let message = resultOptions; | ||
if (arr.length - 1 === i) { | ||
resultOptions = message.concat(`{"type": "${e.type}", "title": "${e.title}"} `); | ||
} | ||
else { | ||
resultOptions = message.concat(`{"type": "${e.type}", "title": "${e.title}"}, `); | ||
} | ||
}); | ||
return this.http.post("/msg", new url_1.URLSearchParams({ | ||
@@ -93,6 +114,41 @@ channel: "whatsapp", | ||
"src.name": sourceName, | ||
message: `${type}` | ||
message: `{ "type": "quick_reply", "content": { ${resultContent} }, "options": [ ${resultOptions} ] }` | ||
})); | ||
} | ||
sendListMessage(source, destination, sourceName, payload) { | ||
let resultItems = ''; | ||
let resultButtons = ''; | ||
let entriesItem = payload.items; | ||
entriesItem.map((e, i, arr) => { | ||
let message = resultItems; | ||
let resultOptions = ''; | ||
let entriesOption = e.options; | ||
entriesOption.map((option, j, array) => { | ||
let messageOption = resultOptions; | ||
if (array.length - 1 === j) { | ||
resultOptions = messageOption.concat(`{"type": "${option.type}", "title": "${option.title}", "description": "${option.description}"} `); | ||
} | ||
else { | ||
resultOptions = messageOption.concat(`{"type": "${option.type}", "title": "${option.title}", "description": "${option.description}"}, `); | ||
} | ||
}); | ||
if (arr.length - 1 === i) { | ||
resultItems = message.concat(`{"title": "${e.title}", "subtitle": "${e.subtitle}", "options": [ ${resultOptions}] }`); | ||
} | ||
else { | ||
resultItems = message.concat(`{"title": "${e.title}", "subtitle": "${e.subtitle}", "options": [ ${resultOptions}]}, `); | ||
} | ||
}); | ||
let entriesButton = payload.globalButtons; | ||
entriesButton.map((e, i, arr) => { | ||
let message = resultButtons; | ||
if (arr.length - 1 === i) { | ||
resultButtons = message.concat(`{"type": "${e.type}", "title": "${e.title}"} `); | ||
} | ||
else { | ||
resultButtons = message.concat(`{"type": "${e.type}", "title": "${e.title}"}, `); | ||
} | ||
}); | ||
let test = `{ "type": "list", "body": "${payload.body}" , "title": "${payload.title}", "globalButtons" : [ ${resultButtons}], "items" : [ ${resultItems}] }`; | ||
console.log(test); | ||
return this.http.post("/msg", new url_1.URLSearchParams({ | ||
@@ -103,5 +159,3 @@ channel: "whatsapp", | ||
"src.name": sourceName, | ||
message: `{ | ||
${payload} | ||
}` | ||
message: `{ "type": "list", "title": "${payload.title}", "body": "${payload.body}", "globalButtons" : [ ${resultButtons}], "items" : [ ${resultItems}] }` | ||
})); | ||
@@ -108,0 +162,0 @@ } |
{ | ||
"name": "gupshup-whatsapp-sdk", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "NodeJS sdk for communicating with gupshup whatsapp api", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15326
374