botpress-broadcast
Provides an interface and APIs to schedule and send messages to your bot audience.
**Support connectors: ** botpress-messenger
Get started
botpress install broadcast
The broadcast module should now be available in your bot UI, and the APIs exposed.
Features
Send according to Users timezone
You can decide wether the scheduled time is abolute to the bot's time or to individual users. If no timezone information available for the user, GMT is chosen.
Send as Javascript snippet
Instead of sending text, you can decide the behavior of the sending function and do basically anything. The function will be called for every message (so for every user).
Variables exposed:
bp
botpress instanceuserId
the userId to send the message toplatform
the platform on which the user is on
The built-in Facebook Messenger snippets are example of Javascript execution (see UI).
Filtering
You can apply filters to the broadcasts. Filters are small javascript functions that will be evaluated before sending the broadcast to a user. The condition is called for every users the broadcast is scheduled to.
Variables exposed to the filter function:
bp
botpress instanceuserId
the userId to send the message toplatform
the platform on which the user is on
The function needs to return a boolean or a Promise of a boolean.
Note: Starting your function with return
is optional.
Examples
Send a message only to users on Facebook
["platform === 'facebook'"]
Send a message only to subscribed users
Note: Assuming your bot has a subscriptions
table that holds userId and platform
bp.isUserSubscribed = (userId, platform) => {
return bp.db.get()
.then(knex =>
knex('subscriptions')
.where({ userId, platform })
.select('count(*) as count')
then().get(0).then(({count}) => count > 0)
)
}
["bp.isUserSubscribed(userId)"]
Roadmap
API
GET /api/botpress-broadcast/broadcasts
Returns a list of the scheduled broadcasts.
PUT /api/botpress-broadcast/broadcasts
Schedules a new broadcast.
Body
{
date: string,
time: string,
timezone: null|int,
type: string,
content: string
filters: [string]
}
Response
"Hello, Human!"
POST /api/botpress-broadcast/broadcasts
Update an existing broadcast. Same as PUT except that id
is also necessary. You can't modify a processing broadcast.
DELETE /api/botpress-broadcast/broadcasts/:id
Delete an existing broadcast. You can't delete a processing broadcast.
Pull requests are welcomed! We believe that it takes all of us to create something big and impactful.
We have a Public Chatroom, everybody is invited to come and share ideas, issues or simply get in touch.
License
botpress-broadcast is licensed under AGPL-3.0