1. Feedback Actions
  2. Update From Whatsapp

Feedback Actions

Update From Whatsapp Feedback Action

A feedback action called by the whatsapp system when a Whatsapp message is received.

Overview

When a Whatsapp message is received by the Stubber Platform the stubsession is derived to intelligently route the message to the correct stub.
Then the _update_from_whatsapp feedback action is triggered on the stub.

The _update_from_whatsapp feedback action is used to then further automate anything in the stub that needs to be done when an email is received.

The message body of the Whatsapp message will be set to the message of the stubpost. i.e. stubpost.message.
If a contact can be derived from the mobile number of the sender, the posted_by => on_behalf_of will be set to the contact.
All the details of the Whatsapp message will be available in the stubpost.data._incoming_whatsapp_data data path.

Data Structure

Feedback Action Data

Example data that is passed to the _update_from_whatsapp feedback action:

        "_incoming_whatsapp_data": {
  "message": "Hi",
  "from": "XXXXXXXXXXXX",
  "from_name": "Joe Soap",
  "to": "14153121456",
  "whatsapp_profile_name": "stubber_public",
  "whatsapp_body": {
    "from": "XXXXXXXXXXXX",
    "id": "wamid.HBgLMjc3MjYwNTAwMzUVAgASGCAwRTlGMzVBQTJDMDY1NzgyRkVCMEM2N0NENzlCNjc5MAA=",
    "timestamp": "1734531943",
    "text": {
      "body": "Hi"
    },
    "type": "text",
    "received_date_time": "2024-12-18T14:25:44.836Z",
    "phone_number_id": "XXXXXXXXXXXX",
    "to": "14153121456",
    "orguuid": "XXXXXXXXXXXXXXX"
  }
},

      

JSONSchema

The JSONSchema of the stubpost.data._incoming_whatsapp_data is :

        {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Incoming WhatsApp Data",
  "type": "object",
  "properties": {
    "_incoming_whatsapp_data": {
      "type": "object",
      "properties": {
        "message": {
          "type": "string",
          "description": "The content or description of the WhatsApp message."
        },
        "whatsapp_attachments": {
          "type": "array",
          "description": "List of attachments included in the WhatsApp message.",
          "items": {
            "type": "object",
            "properties": {
              "filename": {
                "type": "string",
                "description": "The name of the file."
              },
              "originalname": {
                "type": "string",
                "description": "The original name of the file as uploaded."
              },
              "fileuuid": {
                "type": "string",
                "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$",
                "description": "UUID of the file."
              },
              "contentType": {
                "type": "string",
                "description": "The MIME type of the file."
              }
            },
            "required": ["filename", "originalname", "fileuuid", "contentType"],
            "additionalProperties": false
          }
        },
        "from": {
          "type": "string",
          "pattern": "^[0-9]{11,15}$",
          "description": "The sender's phone number in international format."
        },
        "from_name": {
          "type": "string",
          "description": "The name of the sender."
        },
        "to": {
          "type": "string",
          "pattern": "^[0-9]{11,15}$",
          "description": "The recipient's phone number in international format."
        },
        "whatsapp_profile_name": {
          "type": "string",
          "description": "The WhatsApp profile name of the sender."
        },
        "whatsapp_body": {
          "type": "object",
          "properties": {
            "from": {
              "type": "string",
              "pattern": "^[0-9]{11,15}$",
              "description": "The sender's phone number in international format."
            },
            "id": {
              "type": "string",
              "description": "Unique identifier for the WhatsApp message."
            },
            "timestamp": {
              "type": "string",
              "pattern": "^[0-9]+$",
              "description": "Unix timestamp when the message was sent."
            },
            "type": {
              "type": "string",
              "enum": [
                "text",
                "image",
                "audio",
                "video",
                "document",
                "location",
                "contact",
                "sticker"
              ],
              "description": "The type of the WhatsApp message."
            },
            "received_date_time": {
              "type": "string",
              "format": "date-time",
              "description": "The ISO 8601 date-time when the message was received."
            },
            "phone_number_id": {
              "type": "string",
              "description": "The ID of the phone number associated with the WhatsApp Business account."
            },
            "to": {
              "type": "string",
              "pattern": "^[0-9]{11,15}$",
              "description": "The recipient's phone number in international format."
            },
            "orguuid": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$",
              "description": "The UUID of the organization."
            },
            "text": {
              "type": "object",
              "properties": {
                "body": {
                  "type": "string",
                  "description": "The text content of the message."
                }
              },
              "required": ["body"],
              "additionalProperties": false
            },
            "image": {
              "type": "object",
              "properties": {
                "mime_type": {
                  "type": "string",
                  "description": "The MIME type of the image."
                },
                "sha256": {
                  "type": "string",
                  "description": "SHA-256 hash of the image."
                },
                "id": {
                  "type": "string",
                  "description": "Identifier for the image."
                }
              },
              "required": ["mime_type", "sha256", "id"],
              "additionalProperties": false
            },
            "audio": {
              "type": "object",
              "properties": {
                "mime_type": {
                  "type": "string",
                  "description": "The MIME type of the audio."
                },
                "sha256": {
                  "type": "string",
                  "description": "SHA-256 hash of the audio."
                },
                "id": {
                  "type": "string",
                  "description": "Identifier for the audio."
                },
                "voice": {
                  "type": "boolean",
                  "description": "Indicates if the audio is a voice message."
                }
              },
              "required": ["mime_type", "sha256", "id", "voice"],
              "additionalProperties": false
            },
            "contacts": {
              "type": "array",
              "description": "List of contact information included in the message.",
              "items": {
                "type": "object",
                "properties": {
                  "emails": {
                    "type": "array",
                    "description": "List of email addresses for the contact.",
                    "items": {
                      "type": "object",
                      "properties": {
                        "email": {
                          "type": "string",
                          "format": "email",
                          "description": "Email address of the contact."
                        },
                        "type": {
                          "type": "string",
                          "enum": ["Home", "Work", "Other"],
                          "description": "Type of the email address."
                        }
                      },
                      "required": ["email", "type"],
                      "additionalProperties": false
                    }
                  },
                  "name": {
                    "type": "object",
                    "properties": {
                      "first_name": {
                        "type": "string",
                        "description": "First name of the contact."
                      },
                      "last_name": {
                        "type": "string",
                        "description": "Last name of the contact."
                      },
                      "formatted_name": {
                        "type": "string",
                        "description": "Full name of the contact."
                      }
                    },
                    "required": ["first_name", "last_name", "formatted_name"],
                    "additionalProperties": false
                  },
                  "org": {
                    "type": "object",
                    "properties": {
                      "company": {
                        "type": "string",
                        "description": "Company where the contact works."
                      },
                      "title": {
                        "type": "string",
                        "description": "Job title of the contact."
                      }
                    },
                    "required": ["company", "title"],
                    "additionalProperties": false
                  },
                  "phones": {
                    "type": "array",
                    "description": "List of phone numbers for the contact.",
                    "items": {
                      "type": "object",
                      "properties": {
                        "phone": {
                          "type": "string",
                          "pattern": "^\\+?[0-9\\s\\-()]{7,20}$",
                          "description": "Phone number of the contact."
                        },
                        "wa_id": {
                          "type": "string",
                          "pattern": "^[0-9]{11,15}$",
                          "description": "WhatsApp ID associated with the phone number."
                        },
                        "type": {
                          "type": "string",
                          "enum": ["MOBILE", "HOME", "WORK"],
                          "description": "Type of the phone number."
                        }
                      },
                      "required": ["phone", "wa_id", "type"],
                      "additionalProperties": false
                    }
                  }
                },
                "required": ["emails", "name", "org", "phones"],
                "additionalProperties": false
              }
            },
            "location": {
              "type": "object",
              "properties": {
                "latitude": {
                  "type": "number",
                  "minimum": -90,
                  "maximum": 90,
                  "description": "Latitude coordinate of the location."
                },
                "longitude": {
                  "type": "number",
                  "minimum": -180,
                  "maximum": 180,
                  "description": "Longitude coordinate of the location."
                }
              },
              "required": ["latitude", "longitude"],
              "additionalProperties": false
            }
          },
          "required": [
            "from",
            "id",
            "timestamp",
            "type",
            "received_date_time",
            "phone_number_id",
            "to",
            "orguuid"
          ],
          "allOf": [
            {
              "if": {
                "properties": {
                  "type": {
                    "const": "text"
                  }
                }
              },
              "then": {
                "required": ["text"],
                "properties": {
                  "text": {
                    "$ref": "#/properties/_incoming_whatsapp_data/properties/whatsapp_body/properties/text"
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "type": {
                    "const": "image"
                  }
                }
              },
              "then": {
                "required": ["image"],
                "properties": {
                  "image": {
                    "$ref": "#/properties/_incoming_whatsapp_data/properties/whatsapp_body/properties/image"
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "type": {
                    "const": "audio"
                  }
                }
              },
              "then": {
                "required": ["audio"],
                "properties": {
                  "audio": {
                    "$ref": "#/properties/_incoming_whatsapp_data/properties/whatsapp_body/properties/audio"
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "type": {
                    "const": "contact"
                  }
                }
              },
              "then": {
                "required": ["contacts"],
                "properties": {
                  "contacts": {
                    "$ref": "#/properties/_incoming_whatsapp_data/properties/whatsapp_body/properties/contacts"
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "type": {
                    "const": "location"
                  }
                }
              },
              "then": {
                "required": ["location"],
                "properties": {
                  "location": {
                    "$ref": "#/properties/_incoming_whatsapp_data/properties/whatsapp_body/properties/location"
                  }
                }
              }
            }
          ],
          "additionalProperties": false
        }
      },
      "required": ["message", "from", "from_name", "to", "whatsapp_profile_name", "whatsapp_body"],
      "additionalProperties": false
    }
  },
  "required": ["_incoming_whatsapp_data"],
  "additionalProperties": false
}