Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(twillio): add message delay config #649

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/channels/src/twilio/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
8 changes: 8 additions & 0 deletions packages/channels/src/twilio/senders/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ms from 'ms'
import { CommonSender } from '../../base/senders/common'
import { TwilioContext } from '../context'

Expand All @@ -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)))
}
}
}
}
2 changes: 1 addition & 1 deletion packages/server/src/channels/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Loading