kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: allow setting default recipient phone number
rodzic
1a34e58e2d
commit
4e389e6150
|
@ -12,7 +12,8 @@ Ensure the following environment variables are set:
|
||||||
|
|
||||||
- `TWILIO_ACCOUNT_SID`: Your Twilio account SID
|
- `TWILIO_ACCOUNT_SID`: Your Twilio account SID
|
||||||
- `TWILIO_AUTH_TOKEN`: Your Twilio auth token
|
- `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.
|
Otherwise, these can be passed directly to the `TwilioConversationClient` constructor.
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ export type TwilioSendAndWaitOptions = {
|
||||||
/**
|
/**
|
||||||
* The recipient's phone number in E.164 format (e.g. +14565551234).
|
* The recipient's phone number in E.164 format (e.g. +14565551234).
|
||||||
*/
|
*/
|
||||||
recipientPhoneNumber: string
|
recipientPhoneNumber?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The text of the message to send.
|
* The text of the message to send.
|
||||||
|
@ -133,11 +133,14 @@ export class TwilioConversationClient {
|
||||||
|
|
||||||
phoneNumber: string
|
phoneNumber: string
|
||||||
botName: string
|
botName: string
|
||||||
|
defaultRecipientPhoneNumber?: string
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
accountSid = process.env.TWILIO_ACCOUNT_SID,
|
accountSid = process.env.TWILIO_ACCOUNT_SID,
|
||||||
authToken = process.env.TWILIO_AUTH_TOKEN,
|
authToken = process.env.TWILIO_AUTH_TOKEN,
|
||||||
phoneNumber = process.env.TWILIO_PHONE_NUMBER,
|
phoneNumber = process.env.TWILIO_PHONE_NUMBER,
|
||||||
|
defaultRecipientPhoneNumber = process.env
|
||||||
|
.TWILIO_DEFAULT_RECIPIENT_PHONE_NUMBER,
|
||||||
apiBaseUrl = TWILIO_CONVERSATION_API_BASE_URL,
|
apiBaseUrl = TWILIO_CONVERSATION_API_BASE_URL,
|
||||||
botName = DEFAULT_BOT_NAME,
|
botName = DEFAULT_BOT_NAME,
|
||||||
ky = defaultKy
|
ky = defaultKy
|
||||||
|
@ -145,6 +148,7 @@ export class TwilioConversationClient {
|
||||||
accountSid?: string
|
accountSid?: string
|
||||||
authToken?: string
|
authToken?: string
|
||||||
phoneNumber?: string
|
phoneNumber?: string
|
||||||
|
defaultRecipientPhoneNumber?: string
|
||||||
apiBaseUrl?: string
|
apiBaseUrl?: string
|
||||||
botName?: string
|
botName?: string
|
||||||
ky?: typeof defaultKy
|
ky?: typeof defaultKy
|
||||||
|
@ -167,6 +171,10 @@ export class TwilioConversationClient {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (defaultRecipientPhoneNumber) {
|
||||||
|
this.defaultRecipientPhoneNumber = defaultRecipientPhoneNumber
|
||||||
|
}
|
||||||
|
|
||||||
this.botName = botName
|
this.botName = botName
|
||||||
this.phoneNumber = phoneNumber
|
this.phoneNumber = phoneNumber
|
||||||
|
|
||||||
|
@ -260,12 +268,18 @@ export class TwilioConversationClient {
|
||||||
public async sendAndWaitForReply({
|
public async sendAndWaitForReply({
|
||||||
text,
|
text,
|
||||||
name,
|
name,
|
||||||
recipientPhoneNumber,
|
recipientPhoneNumber = this.defaultRecipientPhoneNumber,
|
||||||
timeoutMs = DEFAULT_TWILIO_TIMEOUT_MS,
|
timeoutMs = DEFAULT_TWILIO_TIMEOUT_MS,
|
||||||
intervalMs = DEFAULT_TWILIO_INTERVAL_MS,
|
intervalMs = DEFAULT_TWILIO_INTERVAL_MS,
|
||||||
validate = () => true,
|
validate = () => true,
|
||||||
stopSignal
|
stopSignal
|
||||||
}: TwilioSendAndWaitOptions) {
|
}: TwilioSendAndWaitOptions) {
|
||||||
|
if (!recipientPhoneNumber) {
|
||||||
|
throw new Error(
|
||||||
|
`Error TwilioConversationClient missing required "recipientPhoneNumber"`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let aborted = false
|
let aborted = false
|
||||||
stopSignal?.addEventListener(
|
stopSignal?.addEventListener(
|
||||||
'abort',
|
'abort',
|
||||||
|
|
Ładowanie…
Reference in New Issue