Skip to main content

Push Notifications

Push notifications are messages that are sent from the server to the user's device even when the user is not actively using the application. These notifications are a way to reach out to users and provide valuable information or updates related to their interests or ongoing conversations. They play a crucial role in keeping users engaged and informed about relevant updates in real-time.

  • This guide provides step-by-step instructions on how to send push notifications using a CURL request-

Prerequisites

Obtain Authentication Token for CURL request

Identify Bot ID

  1. Retrieve the Bot ID from the pgAdmin database.
    • Navigate to pgAdmin.
    • Select the aistudiobot_bot table.
    • Locate the appropriate Bot ID.

User ID Retrieval

  1. Retrieve the user ID from pgAdmin database
    • Navigate to pgAdmin
    • Select the aistudiobot_chatsession table.
    • Locate the appropriate User ID

Service url for CURL request

  1. The service urls for different channels are given below,
    • MS teams - "https://smba.trafficmanager.net/in"
    • Azure webchat - "https://webchat.botframework.com"
    • AE webchat - "http://localhost:3978/v3/directline"
    • AE whatsapp - "http://localhost:3978/whatsapp"

Create a Dialog for Push Notification

  1. Within AIStudio, you can create a dialog that includes details of notification, utilizing key-value pairs as dialog parameters in the CURL request.

It's important to note that when a notification is initiated during an ongoing conversation, the system queues the notification. The queued notification is then delivered to the user once they exit the dialog, ensuring timely and non-intrusive communication.

Sending Push Notifications

Construct CURL Request

  • Use the obtained authentication header, Bot ID, and other necessary details to construct a CURL request. Replace placeholders such as {{auth_header}}, {{bot_id}}, {{user_id}}and {{service_url}} with the actual values. Also include the corresponding dialog name and dialog parameters.

     curl -X POST \
    "Authorization": "Bearer {{auth_header}}" \
    '{
    "notifications": [
    {
    "bot_id": "{{bot_id}}",
    "chat_channel": "channel",
    "user_id": "{{user_id}}",
    "service_url": "{{service_url}}",
    "trigger_aistudio_dialog": {
    "dialog_id": "dialogname",
    "params": {
    "key1": "value1",
    "key2": "value2"
    }
    }
    }
    ]
    }' \
    https://your-chatbot-api-endpoint/api/push-notifications