UNPKG

tyntec-sdk

Version:

TypeScript SDK for Tyntec Conversations API V3

113 lines (112 loc) 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createMessageApi = createMessageApi; const models_1 = require("../models"); function createMessageApi(requestHttp, cfg) { const post = (message) => requestHttp.send('POST', '/messages', message); return { async sendMessage(message) { return post(message); }, async sendTextMessage(from, to, text) { return post({ from, to, channel: 'whatsapp', content: { contentType: 'text', text, }, }); }, async sendImageMessage(from, to, url, caption) { return post({ from, to, channel: 'whatsapp', content: { contentType: 'image', image: { url, caption, }, }, }); }, async sendVideoMessage(from, to, url, caption) { return post({ from, to, channel: 'whatsapp', content: { contentType: 'video', video: { url, caption, }, }, }); }, async sendDocumentMessage(from, to, url, caption, filename) { return post({ from, to, channel: 'whatsapp', content: { contentType: 'document', document: { url, caption, filename, }, }, }); }, async sendAudioMessage(from, to, url) { return post({ from, to, channel: 'whatsapp', content: { contentType: 'audio', audio: { url, }, }, }); }, async sendStickerMessage(from, to, url) { return post({ from, to, channel: 'whatsapp', content: { contentType: 'sticker', sticker: { url, }, }, }); }, async sendTemplateMessage(from, to, templateId, templateLanguage, components) { return post({ from, to, channel: 'whatsapp', content: { contentType: 'template', template: { templateId, templateLanguage, components, }, }, }); }, async sendWhatsAppMessage(message) { // Validate the entire message using messageSchema const validatedMessage = models_1.messageSchema.parse(message); return post(validatedMessage); }, }; }