diff --git a/packages/channels/src/twilio/config.ts b/packages/channels/src/twilio/config.ts index ee4d450f4..91286477a 100644 --- a/packages/channels/src/twilio/config.ts +++ b/packages/channels/src/twilio/config.ts @@ -4,9 +4,11 @@ import { ChannelConfig } from '../base/config' export interface TwilioConfig extends ChannelConfig { accountSID: string authToken: string + messageDelay?: string } export const TwilioConfigSchema = { accountSID: Joi.string().regex(/^AC.*/).required(), - authToken: Joi.string().required() + authToken: Joi.string().required(), + messageDelay: Joi.string().optional() } diff --git a/packages/channels/src/twilio/senders/common.ts b/packages/channels/src/twilio/senders/common.ts index 7a7378d9f..ab472c66b 100644 --- a/packages/channels/src/twilio/senders/common.ts +++ b/packages/channels/src/twilio/senders/common.ts @@ -1,3 +1,4 @@ +import ms from 'ms' import { CommonSender } from '../../base/senders/common' import { TwilioContext } from '../context' @@ -9,6 +10,13 @@ export class TwilioCommonSender extends CommonSender { from: context.identity, to: context.sender }) + + const { messageDelay } = context.state.config + if (messageDelay) { + // depending on the account it might be required to limit the rps to each number + // usually this is an issue for carousels + await new Promise((resolve) => setTimeout(resolve, ms(messageDelay))) + } } } } diff --git a/packages/server/src/channels/api.ts b/packages/server/src/channels/api.ts index be3964875..c373b6962 100644 --- a/packages/server/src/channels/api.ts +++ b/packages/server/src/channels/api.ts @@ -34,7 +34,7 @@ export class ChannelApi { channel.on('message', async (e) => this.handleChannelMessage(channel, e)) channel.on('proactive', async (e) => this.handleChannelProactive(channel, e)) - await channel.setup(router) + await channel.setup(router, channel.logger) } }