Skip to main content

REFERENCE

Developer Reference

Authentication, APIs, SDKs, Flow Agent processors and parameter resolution, in full.

Action Object — EMIT

An EMIT action lets the host page handle a button's custom event.

  1. Basic usage​

    When the user taps the button, the SDK calls onTemplateBtnClick(payload, eventName, raw), which the host page passes in. raw is the original message as a JSON string. When the host page does not pass this callback, the button does nothing. The SDK sends no request to the backend.

  2. Structure​

    JSON​

    {
    "type": "EMIT",
    "eventName": "product_inquiry",
    "payload": {
    "productId": "P001",
    "category": "electronics"
    }
    }

    Properties​

    type (required)​

    The action's type, always "EMIT".

    eventName (required)​

    The event's name. Underscore-separated names such as product_inquiry are the convention.

    payload (optional)​

    The data the event carries, in any structured form.

  3. Examples​

    To send a button with an EMIT action from Push Message:

    1. Choose Expression in the Template field's dropdown.
    2. Enter the following JavaScript in the editor.

    A support triage menu​

    (() => {
    return {
    type: 'BUTTON',
    title: 'Support options',
    text: 'Which kind of help do you need?',
    buttons: [
    {
    label: 'Technical support',
    action: {
    type: 'EMIT',
    eventName: 'support_request',
    payload: {
    category: 'technical',
    priority: 'normal',
    },
    },
    },
    {
    label: 'Billing',
    action: {
    type: 'EMIT',
    eventName: 'support_request',
    payload: {
    category: 'billing',
    priority: 'high',
    },
    },
    },
    ],
    };
    })()

    A product enquiry flow​

    (() => {
    return {
    type: 'BUTTON',
    title: 'Product services',
    text: 'Choose what you need:',
    buttons: [
    {
    label: 'See the details',
    action: {
    type: 'EMIT',
    eventName: 'product_inquiry',
    payload: {
    productId: 'laptop_001',
    inquiryType: 'details',
    },
    },
    },
    {
    label: 'Book now',
    action: {
    type: 'EMIT',
    eventName: 'booking_flow_start',
    payload: {
    serviceType: 'restaurant',
    restaurantId: 'brown_cafe_001',
    priority: 'high',
    },
    },
    },
    ],
    };
    })()

Ready to get started?

Want to see how Asgard fits your team? Talk to us.

Contact us