Invoking a Cloud Function

When invoking a Cloud Function, Stackchat provides clearly structured data to support the execution of the function. Two arguments are delviered to the function:

`userData' is provided every time a cloud function is invoked and contains the contents of all Meta and Custom Slots as below.

               //  userData -
               //    - metaData -
               //          - userId
               //          - signedUpAt
               //          - conversationStarted
               //          - isAuthenticated
               //          - email
               //          - givenName
               //          - surname
               //          - lastUtterance
               //          - rawNlpResponse
               //          - previousFlow
               //          - currentFlow
               //    - slotData -
               //        - All custom slot variables

Which Meta Slots are filled will vary depending on the Channel in which your bot is present.

Special attention should be paid to the rawNlpResponse Meta Slot. If your bot has methods of reaching a Flow through NLP-based navigation or active navigation, the data in this slot may be stale, as it will always contain the most recent response from your NLP service.

The rawNlpResponse appears in the format below.


dateReceived can be used to validate the time and confirm that the NLP response is related to the invoked Cloud Function, while the responseData will vary depending on the NLP service used.

The second argument that will be sent through is a postBackPayload. This will only be passed when the Cloud Function is invoked via a postback carousel button and will return that button's payload. This can be used to perform functions such as returning a product ID. In the case that the Cloud Function is invoked via another method, this will not be included in the arguments.

Your Cloud Function can now perform its programming and return result(s) via the Dynamic Content Toolkit. In most cases, this will be done via an async call to your business API, which can be returned with a promise, Promise<dc.DynamicContentItem[]>. In rare cases where your dynamic content has already been populated, you can instead use dc.DynamicContentItem[].