From 4e389e61506046197b217b527d9e5bc86843457b Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 13 Jun 2023 12:38:46 -0400 Subject: [PATCH] feat: allow setting default recipient phone number --- legacy/docs/twilio.md | 3 ++- legacy/src/services/twilio-conversation.ts | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/legacy/docs/twilio.md b/legacy/docs/twilio.md index ad93df65..7690234b 100644 --- a/legacy/docs/twilio.md +++ b/legacy/docs/twilio.md @@ -12,7 +12,8 @@ Ensure the following environment variables are set: - `TWILIO_ACCOUNT_SID`: Your Twilio account SID - `TWILIO_AUTH_TOKEN`: Your Twilio auth token -- `TWILIO_PHONE_NUMBER`: Your Twilio phone number +- `TWILIO_PHONE_NUMBER`: Your Twilio phone number from which the Agentic service will send text messages +- `TWILIO_DEFAULT_RECIPIENT_PHONE_NUMBER`: The default recipient phone number to use if none is specified in the workflow Otherwise, these can be passed directly to the `TwilioConversationClient` constructor. diff --git a/legacy/src/services/twilio-conversation.ts b/legacy/src/services/twilio-conversation.ts index d3c691ef..31e65414 100644 --- a/legacy/src/services/twilio-conversation.ts +++ b/legacy/src/services/twilio-conversation.ts @@ -90,7 +90,7 @@ export type TwilioSendAndWaitOptions = { /** * The recipient's phone number in E.164 format (e.g. +14565551234). */ - recipientPhoneNumber: string + recipientPhoneNumber?: string /** * The text of the message to send. @@ -133,11 +133,14 @@ export class TwilioConversationClient { phoneNumber: string botName: string + defaultRecipientPhoneNumber?: string constructor({ accountSid = process.env.TWILIO_ACCOUNT_SID, authToken = process.env.TWILIO_AUTH_TOKEN, phoneNumber = process.env.TWILIO_PHONE_NUMBER, + defaultRecipientPhoneNumber = process.env + .TWILIO_DEFAULT_RECIPIENT_PHONE_NUMBER, apiBaseUrl = TWILIO_CONVERSATION_API_BASE_URL, botName = DEFAULT_BOT_NAME, ky = defaultKy @@ -145,6 +148,7 @@ export class TwilioConversationClient { accountSid?: string authToken?: string phoneNumber?: string + defaultRecipientPhoneNumber?: string apiBaseUrl?: string botName?: string ky?: typeof defaultKy @@ -167,6 +171,10 @@ export class TwilioConversationClient { ) } + if (defaultRecipientPhoneNumber) { + this.defaultRecipientPhoneNumber = defaultRecipientPhoneNumber + } + this.botName = botName this.phoneNumber = phoneNumber @@ -260,12 +268,18 @@ export class TwilioConversationClient { public async sendAndWaitForReply({ text, name, - recipientPhoneNumber, + recipientPhoneNumber = this.defaultRecipientPhoneNumber, timeoutMs = DEFAULT_TWILIO_TIMEOUT_MS, intervalMs = DEFAULT_TWILIO_INTERVAL_MS, validate = () => true, stopSignal }: TwilioSendAndWaitOptions) { + if (!recipientPhoneNumber) { + throw new Error( + `Error TwilioConversationClient missing required "recipientPhoneNumber"` + ) + } + let aborted = false stopSignal?.addEventListener( 'abort',