4.4.0-beta
This is a function reference for mailbots-sdk-js. View the readme.md file in the the repo that corresponds with this version. Also, view MailBots REST API and the MailBots API Docs for more information.
Low-level function to make authenticated request to MailBots API
Promise
:
Factory method to return a new, fully authenticated MailBots client based on the webhook
mailbot.onCommand('foo', bot => {
const mbClient = MailBotsClient.fromBot(bot);
})
Get information about the bot that corresponds with user's Bearer token (ie, most likely your bot).
(function?)
Optional callback
Promise
:
const res = await mbClient.mailbotGetSelf();
Send an Event to the bot. This does not require and auth token because the endpoint is meant for 3rd party services. Ex: issue created in Github, or an email response or support ticket received. The MailBots bot can listen for events, act on tasks or create or delete tasks based on events.
(object)
params
(any)
Promise
:
const res = await mbClient.sendEvent({type: 'event.type', payload: {"foo", "bar"}, event_url: "[unique_event_url]"});
An "Interbot Event" allows bots to send messages to each other. This allows a MailBot to expose actions that can be utilized by other MailBots (for example, creating an Evernote note) In this way, MailBots can become composable. Requires elevated oauth scope.
Promise
:
const res = await mbClient.sendInterbotEvent({subdomain: 'git', payload: {"foo", "bar"}});
Save MailBot data which is sent with every webhook related to that bot. This is how a bot persist's user settings specific to that bot. For params and details, see bot saving data API docs
(object)
Nestable key value value pairs
(any)
Promise
:
const res = await mbClient.saveBotData({ foo: "bar" });
Get saved MailBot data For params and details, see mailbots get data API docs
(any)
const res = await mbClient.getBotData();
Get a filtered list of People
Promise
:
// Get all people
const res = await mbClient.searchPeople();
console.log(res.people);
// With a callback
mbClient.searchPeople({ limit: 1 }, (err, res) => {
if (err) done(err);
console.log(res.people);
});
Create a new person.
(any)
(function?)
Optional callback function
Promise
:
Get a person by it's ID.
Promise
:
// Get person with id 3
const res = await mbClient.getPersonById(3);
console.log(res.person);
Update a person by id.
Promise
:
Update multiple people with a single batch operation.
Promise
:
Create a new person event.
(object)
Name | Description |
---|---|
params.type string
|
The type of this event |
params.title string
|
Title of the event |
params.body string
|
Event content |
params.links array
|
Event content |
(any)
Promise
:
Update a person's tags attribute by id.
(object)
Arguments for API call
Name | Description |
---|---|
params.newTags Array<string>
|
|
params.replace boolean
|
keep exising tags or replace them |
(function?)
Optional callback function
Promise
:
Merge one or more people into a base person.
(object)
Name | Description |
---|---|
params.basePersonId number
|
Id of the person to merge into |
params.mergePersonIds Array<number>
|
Ids of people to merge with |
(any)
Promise
:
Get a filtered list of MailBots tasks
(object)
Arguments for API call
Name | Description |
---|---|
params.suppress_webhook boolean
|
Prevent MailBots from firing the task.viewed webhook |
params.status boolean
|
Retrieve completed or open tasks |
(function?)
Optional callback function
Promise
:
// Get all open tasks, sorted by due date
const res = await mbClient.getTasks();
console.log(res.tasks);
// With a callback
mbClient.getTasks({ limit: 1 }, (err, res) => {
if (err) done(err);
console.log(res.tasks);
});
Get a MailBots task Passing ?verbose=1 fires a webhook to the extnesion and fetches a rendered HTML email preview of the task
(object)
request params
Name | Description |
---|---|
params.id number
|
taskid |
params.verbose boolean
|
Fires webhook to bot, returns rendered HTML emails in a "messages" array if the bot makes these available in the task.viewed webhook resopnse. |
(any)
Promise
:
const res = await getTask({id: 123});
Create a new MailBots Task.
(any)
(any)
(any)
Promise
:
const res = await mbClient.createTask(
{
webhook: false,
suppress_email: true,
verbose: 1,
task: {
command: process.env.EXAMPLE_COMMAND
},
send_messages: [
{
type: "email",
subject: "A test email message",
to: "test@example.com",
body: [
{
type: "html",
html: "<h1>This is a test</h1>"
}
]
}
]
});
Send email and automatically create a Task This creates a MailBots task and sends an email. It's a wrapper for createTask with opinionated settings for just sending email.
(any)
Promise
:
const res = await mbClient.sendEmail({
command: "command@my-ext.eml.bot", // must be your bot's domain
to: "test@exampletask.com",
cc: [],
bcc: [],
from: "test@example.com",
subject: "Test1",
body: [
{
type: "html",
text: "<h1>This is a test</h1>"
}
]
});
Send emails relating to an existing Task. Does not mutate task. NOTE: This may be deprecated in favor of sending messages via the update task endpoint.
const res = await mbClient.sendMessages({
task: {
id: 123
},
send_messages: [{
to: "test@exampletask.com",
cc: [],
bcc: [],
from: "test@example.com",
subject: "Test1",
body: [
{
type: "html",
text: "<h1>This is a test</h1>"
}
]
}]
});
Update A MailBots Task Used to save data against the task, update content, followup time and more
(any)
(any)
(any)
Promise
:
const res = await mbClient.updateTask({
task: {
id: 1234,
reference_email: {
to: "newRecipient@exampletask.com"
}
}});
Archive A MailBots Task
(number)
Arguments
Name | Description |
---|---|
params.task number
|
Task object |
params.task.id number
|
Task id to complete |
(any)
Promise
:
Permanently Delete A MailBots Task
(object)
Task to delete
Name | Description |
---|---|
params.task object
|
Task object |
params.task.id number
|
Task id to delete |
(any)
Promise
:
Trigger a MailBots Task
(object)
Name | Description |
---|---|
params.trigger_url boolean
|
Trigger URL of the task to trigger (get from task object) |
params.verbose boolean?
|
Fire webhook and render HTML email response |
(any)
Promise
:
Resolve Natural Time Format (ex: {naturaltime}@ext.eml.bot)
(object)
params object
Name | Description |
---|---|
params.format string
|
Time format to check (ex: 3days) |
params.timezone string
|
IANA timezone designation ( https://www.wikiwand.com/en/List_of_tz_database_time_zones ) ex: "America/Los_Angeles" |
(any)
Promise
:
Dispatch an email-based action for a task. (Equivalent to sending an action email.)
(object)
Name | Description |
---|---|
params.action string
|
The action string |
params.reference_email object
|
The email that would be sent as the action email |
params.verbose boolean?
|
Include rendered HTML email contents in API response |
(any)
Promise
:
Create a new task event.
(object)
Name | Description |
---|---|
params.type string
|
The type of this event |
params.data object
|
Data associated with this event. |
(any)
Promise
:
Get information about the currently logged in user
(function?)
Optional callback
Validate webhook signature. Set verifyAge to false when testing / mocking HTTP requests. (Server side only)
(string)
(number)
Unix Timestamp of webhook. Used to prevent reply attack
(string)
Unprocessed http post body
(boolean?
= true
)
Use for automated testing
boolean
:
Pass / fail webhook validation