Payload

Learn more about the information that you can add to your code action.

A code action is a function that executes with a payload. The payload includes metadata about the message information and the user who triggered the action.

You can use the payload to use the conversation ID to connect with the care API, manipulate data, and view the data.

The payload includes the following metadata information:

Payload Contents

The payload includes metadata that provides contextual information about the triggered action.
The code below is the code snippet of the payload information.

/**
@param {object} payload - data and info
@param {string} payload.threadId - Identifier for the conversation
@param {string} payload.channelName - type of channel
@param {string} payload.query - what the user sends
@param {object} payload.params - data detected by AI
@param {object} payload.user - user that triggered the action
@param {string} payload.user.name - name of the user
@param {string} [payload.user.profile.firstName] - first name of the user
@param {string} [payload.user.profile.lastName] - Last name of the user
@param {string} [payload.user.profile.fullName] - first and last name combined
@param {string} [payload.user.profile.picture] - profile picture
@param {string} [payload.user.profile.locale] - user language
@param {string} [payload.user.profile.gender] - user gender
@param {object} payload.match - matching flow and step
@param {object} payload.match.flow - contains name and flowId of matching flow
@param {object} payload.match.step - contains name and stepId of matching step
*/
async payload => {
    // Your custom logic
}

An actual example of the payload:

{
  "type": "action",
  "threadId": "8bfc0cb8-680f-45e1-8113-f46c77e3829e",
  "channelName": "gateway",
  "channelId": "a9T9J_Aun",
  "query": "check payload",
  "action": "Untitled Code 1",
  "actions": [
    "Untitled Code 1"
  ],
  "intents": [],
  "contexts": [],
  "params": {},
  "originator": {
    "userId": "flowai|system",
    "name": "system",
    "role": "bot",
    "profile": {
      "picture": "https://flow.ai/img/brains/flowai.svg"
    }
  },
  "user": {
    "_id": "6791d564debee900230eedfe",
    "agentId": "a9T9J_Aun",
    "handles": [
      {
        "_id": "6791d564debee900230eedfc",
        "userId": "8bfc0cb8-680f-45e1-8113-f46c77e3829e",
        "channelName": "gateway"
      }
    ],
    "__v": 0,
    "activeAt": "2025-01-23T05:36:36.075Z",
    "actorId": "8bfcbb10-b1e6-47b1-bd2c-0efcb3254c94",
    "channelName": "gateway",
    "createdAt": "2025-01-23T05:36:36.075Z",
    "expires": "2025-01-23T05:51:36.075Z",
    "isActive": true,
    "isImported": false,
    "lang": "und",
    "metadata": {},
    "name": "Priyanka Barnwal",
    "profile": {
      "fullName": "Priyanka Barnwal",
      "firstName": "Priyanka",
      "lastName": "Barnwal",
      "email": "priyanka.barnwal@khoros.com",
      "locale": "en",
      "timezone": "5.5",
      "gender": "U"
    },
    "role": "external",
    "sub": false,
    "tags": [],
    "tagsHistory": [],
    "updatedAt": "2025-01-23T05:36:36.075Z"
  },
  "metadata": {
    "language": "en-GB",
    "timezone": 5.5,
    "contexts": [],
    "params": {},
    "domain": {
      "realm": "browser",
      "title": "Flow.ai Dashboard",
      "url": "https://app.flow.ai/a9T9J_Aun/actions/i4NdpFieY/function#preview",
      "pathname": "/a9T9J_Aun/actions/i4NdpFieY/function",
      "origin": "https://app.flow.ai",
      "hostname": "app.flow.ai",
      "language": "en-GB",
      "platform": "MacIntel"
    }
  },
  "match": {
    "brain": {
      "brainId": "46b121f5-cd03-4578-8f0f-df7650731e5c",
      "brainName": "flowai-v2",
      "brainLanguage": "en",
      "brainRegion": "US",
      "language": "en"
    },
    "flow": {
      "flowId": "f1L-A_7ON",
      "title": "Untitled 4",
      "group": "Default",
      "versionsMetadata": {
        "flowImmutableId": "f-7k-OSLe"
      },
      "metadata": []
    },
    "step": {
      "stepId": "spmFysibh",
      "title": "check paylaod",
      "type": "INTENT"
    },
    "sentiment": 0,
    "classification": {
      "intents": [],
      "entities": [],
      "unmatched": []
    },
    "entities": [],
    "channelsScope": [
      "socket"
    ],
    "accuracy": 0
  },
  "args": {}
}

We've provided a breakdown of the payload's included information below:

threadId

The threadId is a unique identifier that represents a conversation. In some channels, this identifier signifies the user. For instance, on Messenger, this corresponds to the page-specific ID (PSID).

channelName

With each conversation, you also receive the type of channel. This is a simple string like socket, whatsApp, or rcs.

📘

Socket API and Web Widget

Both the Socket API and Web widget are the socket channels.

query

Query provides instructions about how an action must be triggered, such as sending a text message. For example, an action is triggered when a user starts a conversation.

params

Parameters include any data extracted by the AI engine or sent through other integrations or channels.

user

This object contains profile information about the user who triggers the Code action. The name field is the only mandatory field.
The user object information is given in the table below:

FieldDescriptionRequired
nameYes
profile.firstNameFirst name of the userNo
profile.lastNameLast name of the userNo
profile.fullNameFull name (First and last name) of the userNo
profile.pictureProfile pictureNo
profile.localeUser languageNo
tagsApplied tags listNo

match

The match object will include both the matched step and the corresponding flow.