whatsapp-api-js
Advanced tools
Comparing version 0.5.0-beta.2 to 0.5.0-beta.3
15
fetch.js
@@ -8,3 +8,3 @@ const { Contacts } = require('./types/contacts'); | ||
const req = typeof fetch === "undefined" ? require('cross-fetch') : fetch; | ||
const req = require('./fetch-picker').pick(); | ||
@@ -39,5 +39,6 @@ /** | ||
constructor(object, to, context) { | ||
let message = { ...object }; | ||
this.messaging_product = "whatsapp"; | ||
this.type = object._; | ||
delete object._; | ||
this.type = message._; | ||
delete message._; | ||
this.to = to; | ||
@@ -49,3 +50,3 @@ | ||
// This horrible thing comes from Contacts, the only API element which must be an array instead of an object... | ||
this[this.type] = JSON.stringify(object[this.type] ?? object); | ||
this[this.type] = JSON.stringify(message[this.type] ?? message); | ||
} | ||
@@ -177,3 +178,7 @@ } | ||
function updateQR(token, v, phoneID, id, message) { | ||
return req(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls/${id}?prefilled_message=${encodeURI(message)}`, { | ||
const params = { | ||
prefilled_message: message, | ||
}; | ||
return req(`https://graph.facebook.com/${v}/${phoneID}/message_qrdls/${id}?${new URLSearchParams(params)}`, { | ||
method: "POST", | ||
@@ -180,0 +185,0 @@ headers: { |
@@ -51,4 +51,4 @@ // Most of these imports are here only for types checks | ||
logSentMessages(callback) { | ||
if (callback && typeof callback !== "function") throw new Error("Callback must be a function"); | ||
this._debug = callback; | ||
if (callback && typeof callback !== "function") throw new TypeError("Callback must be a function"); | ||
this._register = callback; | ||
return this; | ||
@@ -75,3 +75,3 @@ } | ||
const { request, promise } = api.sendMessage(this.token, this.v, phoneID, to, object, context); | ||
if (this._debug) this._debug(phoneID, request.to, JSON.parse(request[request.type]), request); | ||
if (this._register) this._register(phoneID, request.to, JSON.parse(request[request.type]), request); | ||
return promise; | ||
@@ -78,0 +78,0 @@ } |
{ | ||
"name": "whatsapp-api-js", | ||
"version": "0.5.0-beta.2", | ||
"version": "0.5.0-beta.3", | ||
"author": "Secreto31126", | ||
@@ -9,6 +9,6 @@ "description": "A Whatsapp Official API helper for Node.js", | ||
"scripts": { | ||
"test": "node --inspect test.js", | ||
"debug": "node --inspect index.js", | ||
"document": "./node_modules/.bin/jsdoc -d ./documentation -t ./node_modules/docdash -R ./README.md . ./types", | ||
"win-document": ".\\node_modules\\.bin\\jsdoc -d ./documentation -t ./node_modules/docdash -R ./README.md . ./types" | ||
"test": "mocha ./tests/", | ||
"coverage": "nyc --reporter=text mocha ./tests/ --reporter min", | ||
"debug-with-tests": "nodemon -x npm run test", | ||
"document": "jsdoc -d ./docs -t ./node_modules/docdash -R ./README.md . ./types" | ||
}, | ||
@@ -27,3 +27,8 @@ "keywords": [ | ||
"docdash": "^1.2.0", | ||
"jsdoc": "^3.6.10" | ||
"jsdoc": "^3.6.10", | ||
"mocha": "^10.0.0", | ||
"nock": "^13.2.7", | ||
"nyc": "^15.1.0", | ||
"rewire": "^6.0.0", | ||
"sinon": "^14.0.0" | ||
}, | ||
@@ -30,0 +35,0 @@ "dependencies": { |
@@ -8,2 +8,3 @@ /** | ||
* @returns {String} The challenge string, it must be the http response body | ||
* @throws {Number} 500 if verify_token is not specified | ||
* @throws {Number} 400 if the request is missing data | ||
@@ -13,2 +14,5 @@ * @throws {Number} 403 if the verification tokens don't match | ||
function get(params, verify_token) { | ||
// verify_token is required | ||
if (!verify_token) throw 500; | ||
// Parse params from the webhook verification request | ||
@@ -91,6 +95,5 @@ let mode = params["hub.mode"]; | ||
const messageID = statuses.id; | ||
const conversation = statuses.conversation; | ||
const pricing = statuses.pricing; | ||
const conversation = value.conversation; | ||
const pricing = value.pricing; | ||
onStatus(phoneID, phone, status, messageID, conversation, pricing, data); | ||
@@ -97,0 +100,0 @@ } |
94806
18
2072
7