Skip to content

Commit

Permalink
feat(twillio): add message delay config (#649)
Browse files Browse the repository at this point in the history
* fix(engine): lock sqlite version

* feat(twillio): add message delay config
  • Loading branch information
davidvitora committed Jan 24, 2024
1 parent fc2a257 commit f12fc4b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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

0 comments on commit f12fc4b

Please sign in to comment.