botbuilder-adapter-tyntec-whatsapp
Version:
A Microsoft Bot Framework adapter for handling connectivity with the WhatsApp channel in tyntec Conversations API.
34 lines (33 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseTyntecSendWhatsAppMessageResponse = exports.composeTyntecRequestConfig = exports.composeTyntecSendWhatsAppMessageRequestConfig = void 0;
function composeTyntecSendWhatsAppMessageRequestConfig(apikey, data) {
return composeTyntecRequestConfig("post", "/conversations/v3/messages", apikey, "application/json", {
contentType: "application/json",
content: data
});
}
exports.composeTyntecSendWhatsAppMessageRequestConfig = composeTyntecSendWhatsAppMessageRequestConfig;
function composeTyntecRequestConfig(method, url, apikey, accept, data) {
const config = {
method,
url: new URL(url, "https://api.tyntec.com").toString(),
headers: {
accept,
apikey
},
};
if (data !== undefined) {
config.data = data.content;
config.headers["content-type"] = data.contentType;
}
return config;
}
exports.composeTyntecRequestConfig = composeTyntecRequestConfig;
function parseTyntecSendWhatsAppMessageResponse(response) {
if (response.status !== 202) {
throw new Error(`Failed to send a WhatsApp message: ${response.status}: ${JSON.stringify(response.data)}`);
}
return response.data.messageId;
}
exports.parseTyntecSendWhatsAppMessageResponse = parseTyntecSendWhatsAppMessageResponse;