Subscribe a Webhook to get WhatsApp flows results

How to configure labels?

  1. Login into the Truora’s platform.
  2. In the sidebar, select Webhooks/Automations.
  3. Click on the “New Rule” button.
  4. Assign the name of the rule, and if you wish, you can add a description.
  5. Select the product “Customer Engagement” and the sub product “WhatsApp Flows”.
    select_product
  6. Select the sub product WhatsApp Flows, which includes three events you can choose from:
    • Started: When the user initiates a WhatsApp flow.
    • Success: When the WhatsApp flow is completed or successful according to the defined conditions.
    • Failed: When the WhatsApp flow is not completed or fails according to the defined conditions.
  7. Save the activator.
    select_event
  8. Optional: Add Conditions based on events and variables. (List of events and their variables and save it.
    add_condition
  9. Select the action “Notification via webhook”.
  10. Configure “Notification via webhook” action.
  • Add an identifier name.
  • Provide an email to notify the Webhook status or changes.
  • Optional: If the endpoint for receiving Webhook notifications requires credentials, be sure to add them.
  • Select the method and provide the URL.
  • Optional: Add the params and headers.

In the body of the request, the response will be sent in JWT format. Later in this guide, a brief context about JWTs is provided.

  1. Save the action and save the rule.
    action_config

What is a JWT?

A JSON Web Token (JWT) is a Base64-encoded string used for authentication and the secure transfer of information between two parties. A JWT consists of three parts separated by periods (.), formatted as «header».«body».«signature».

Example:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.83a9Oh1v7AAKfEr4BXxZC44gNiOb_OJ7PI3mEO4rwXE
  • Header: Contains the type of token and the encryption algorithm used.
  • Payload: Includes the information to be transmitted, usually in JSON format.
  • Signature: Ensures the integrity of the token, allowing verification that the JWT was issued by the legitimate source and has not been tampered with.

How to Decode a JWT?

There are several libraries available in different programming languages that allow you to decode and verify a JWT. Some of the most popular include jsonwebtoken for JavaScript, jwt-simple for Python, and jjwt for Java, among others.

In this guide, an example will be provided using the jsonwebtoken library in JavaScript.

To decode and verify a JWT, you can use the jwt.verify(…) function from jsonwebtoken. This function takes the token as the first argument and the secret key used to generate the signature as the second argument. If the signature and algorithm match, the token is valid; otherwise, it will be considered tampered with.

Example

    const jwt = require("jsonwebtoken");
    
    function parseJwt (token) {
       try {
           const decoded = jwt.verify(token, "c48863adab6b101b79f08ddb2cfe1b1c3f2ff7eb38fa01a14904dde971c2193b");
           console.log(JSON.stringify(decoded, null, "\t"));
         } catch (err) {
           console.log(err);
         }
    }

    parseJwt(
     "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.83a9Oh1v7AAKfEr4BXxZC44gNiOb_OJ7PI3mEO4rwXE"
    );