Last active
January 20, 2024 21:07
-
-
Save IgorHalfeld/ef8bc20d8a6bc344b6366207a18a2803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import twilio from 'twilio' | |
import { MessageListInstanceCreateOptions } from 'twilio/lib/rest/api/v2010/account/message' | |
interface SendWhatsappMessageOptions { | |
to: string | |
from: string | |
body?: string | |
contentSid?: string | |
contentVariables?: Record<string, string> | |
accountSid: string | |
authtoken: string | |
} | |
export const sendWhatsappMessage = async (options: SendWhatsappMessageOptions) => { | |
const client = twilio(options.accountSid, options.authtoken) | |
options.to = `whatsapp:${options.to}` | |
/* | |
* should on this way if not using twilio message service | |
* options.from = `whatsapp:${options.from}` | |
*/ | |
const payload: MessageListInstanceCreateOptions = { | |
to: options.to, | |
from: options.from, | |
contentSid: options.contentSid, | |
contentVariables: options.contentVariables && JSON.stringify(options.contentVariables), | |
} | |
const message = await client.messages.create(payload) | |
return message | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment