Skip to main content
The Inject Transformer converts the webhook payload from an external service before you call an Inject API request, which sends the data to the Flow. With the inject transformer, you don’t need a service that translates the webhook payload of the external service into the correct format for the Inject API request. You can handle this conversion in the inject transformer by parsing the payload to return only the necessary values. You can configure the inject transformer in the handleInject function in the Endpoint settings or via CLI.

Restrictions

  • The inject transformer is supported only for webhook- and socket-based Endpoints.
  • The return value is validated against a set of rules. If these rules aren’t met, the transformer throws an error. The following rules apply:
    • userId is a string with up to 256 characters.
    • sessionId is a string with up to 256 characters.
    • text is a string with up to 10,000 characters.
    • data is an object.

Transformer Function Arguments

The following table shows an overview of the function arguments:
ArgumentDescription
endpointThe configuration object for the Endpoint.
requestThe Express request object with a JSON-parsed body.
responseThe Express response object.

Endpoint Configuration Object

PropertyTypeDescription
_idstringThe Endpoint’s Reference ID.
channelstringThe Endpoint’s channel.
URLTokenstringThe URL Token, found in the Input object.
namestringThe Endpoint’s name.
flowIdstringThe Reference ID of the specified Flow to which the Endpoint points to.
entrypointstringThe Entrypoint of the Endpoint.
activebooleanThe flag to activate or deactivate the Endpoint.
nluConnectorIdstringID of the selected NLU connector for the Endpoint.
useAnalyticsbooleanThe flag to collect analytics data for the Endpoint.
storeDataPayloadbooleanThe flag to store data payloads into analytics for the Endpoint.
useConversationsbooleanThe flag to collect conversations history for the Endpoint.
maskIPAddressbooleanThe flag to mask sensitive IP addresses in input object and analytics data.
maskAnalyticsbooleanThe flag to mask sensitive data in analytics for the Endpoint.
maskLoggingbooleanThe flag to mask sensitive data in logs for the Endpoint.
useContactProfilesbooleanThe flag to use Contact Profiles for the Endpoint.
useDashbotAnalyticsbooleanThe flag to use Dashbot for collecting analytics data.
dashbotApikeystringThe API key of the Dashbot bot for analytics collection.
dashbotPlatformstringThe selected platform of the Dashbot bot for analytics collection.
settingsobjectOptional Endpoint-specific settings. For example, Facebook Page token.
handoverSettingsobjectSettings to configure a handover provider.
createdAtnumberUnix timestamp when the Endpoint was created.
lastChangednumberUnix timestamp when the Endpoint was last modified.
createdBystringEmail of the user who created the Endpoint.
lastChangedBystringEmail of the user who last modified the Endpoint.

Return Values

The inject transformer returns a valid user ID, session ID, text, and data. These return values need to match the format of the payload of the Endpoint you are using. The payload format is specific to the Endpoint type you use, for example, Alexa or Facebook (Meta) Messenger. Read the documentation of the specific Endpoint to know how to format the payload. If the inject transformer returns a falsy value, the output is discarded and not sent to the Inject API request. Here is an example of the correct return format for a webhook-based Endpoint:
handleInject: async ({ endpoint, request, response }) => {
    const webhookPayload = request.body;
    
    // Parse the webhook payload and extract necessary data
    const userId = webhookPayload.user.id;
    const sessionId = webhookPayload.session.id;
    const text = webhookPayload.message.text;
    const data = {
        source: webhookPayload.source,
        timestamp: webhookPayload.timestamp
    };
    
    return {
        userId,
        sessionId,
        text,
        data
    };
}
I