createDraft

Open a composer with a new draft message.

function createDraft(draft: object, cancelToken?: CancelToken): Promise<DraftMessage>;

Parameters

ParameterTypeDescription
draftObjectProperties of the draft to create.
draft.channelIdString (optional)ID of the channel to use to compose the draft. If omitted, Front will apply its internal logic to pick the most relevant channel.
draft.toArray of String (optional)Handles to send the message to.
draft.ccArray of String (optional)Handles to add in copy of the message. Supported only for email channels.
draft.bccArray of String (optional)Handles to add in blind copy of the message. Supported only for email channels.
draft.subjectString (optional)Subject of the message.
draft.contentObject (optional)Content properties of the draft.
draft.content.bodyStringContent of the message.
draft.content.typeStringContent type of the body. Can be either html or text.
draft.attachmentsArray of File (optional)Files to attach to the message. Must contain absolute file paths.
draft.replyOptionsObject (optional)Options to create a draft from another message.
draft.replyOptions.typeStringType of the reply. Can be one of reply, replyAll or forward.
draft.replyOptions.originalMessageIdStringID of the message to reply to or forward.
cancelTokenCancelToken (optional)Token to cancel the request.

Content type

The type of the draft.content.body property is defined in draft.content.type. It can be either text or html.
Front will convert the content in a format that matches the teammate's composer preferences.

Reply options

By default, createDraft will open a composer for a new message.
To create a reply or forward a message, the function accepts an optional draft.replyOptions object. with a originalMessageId and a type. The type property can be one of:

  • reply to reply to the sender of the original message. Front will address the message to the sender by default.
  • replyAll to reply to all recipients of the original message. Front will reuse its recipients by default.
  • forward to forward the original message. Front will reuse its content by default.

Return value

The function returns a promise that resolves with the Draft created.

Examples

const draft = await Front.createDraft({
  to: ['[email protected]'],
  content: {
    body: 'Hello world',
    type: 'text'
  }
});
const draft = await Front.createDraft({
  content: {
    body: 'Hello world',
    type: 'text'
  },
  replyOptions: {
    type: 'reply', // Or 'replyAll'
    originalMessageId: 'msg_xxx'
});
const draft = await Front.createDraft({
  replyOptions: {
    type: 'forward',
    originalMessageId: 'msg_xxx'
});