Sunbird UCI
  • Overview of Sunbird UCI
  • 📙Learn
    • UCI use cases
    • UCI for Education(Case study)
    • Tech Overview
      • Glossary
      • High-level Architecture Design
      • Design Principles
      • Standards
  • 🚀Use
    • Choose your Persona
    • Adopter - Install and use UCI
      • Pre-requisites, Installation Setup, Post Setup
      • Setting up your very first conversation
      • API Documentation
      • Data Exhaust and Analytics
      • Posthog Event
      • Whatsapp (Netcore)
      • Environment Variables
    • Developer - Contribute to UCI
      • UCI Basics
        • XMessage Specification
        • Transformers
          • ODK Transformer
            • Interactive-Messages
            • Media Messages
            • Location
          • Broadcast Transformer
        • Adapters
          • Firebase Notification Adapter
        • User Segment
        • Schema Overview
          • UCI Core Schema
            • XMessage Schema
            • Assessment DB Schema
          • UCI API Schema
      • Development environment
        • Backend Setup
        • Setting up IDE
        • Environment variable setup
        • Debug services
        • Build and Execute UCI
        • Frontend Setup (Admin Console)
        • Frontend Setup (PWA)
        • Transport Socket
      • API Documentation
        • Bot Setup APIs
        • History APIs
        • Direct Message APIs
        • Vault APIs
      • Database Schema
        • Cassandra Xmessage Database
        • Postgres Forms Database
        • Postgres User Analytics Database
        • Postgres Comms Database
      • Contribution Guide
        • Your first PR
        • Contribute an Adapter
        • Adapter Implementation
        • Create a Transformer
    • Contact the administrator
  • ✅Releases
    • Release V2
  • 🤝Engage
    • Software License
    • Acceptable Use Policy
    • Terms of Service
    • Source Code
    • Discussion Forum
Powered by GitBook
On this page
  • 1. Overview
  • 2. APIs
  • 2.1 Netcore Whatsapp Message
  • 2.2 Gupshup Whatsapp Message
  • 2.3 Firebase Web Message
  • 2.4 Gupshup SMS
  • 2.4 CDAC SMS

Was this helpful?

Edit on GitHub
  1. Use
  2. Developer - Contribute to UCI
  3. API Documentation

Direct Message APIs

1. Overview

Send direct messages from outbound service. This api used below parameters to send message to devices.

  • adapterId: Id of adapter added for provider & channel Eg. Gupshup-Whatsapp/Netcore-Whatsapp etc.

  • to.userID: Phone number of user

  • to.deviceType: device type of user Eg. PHONE

  • to.meta.fcmToken: FCM token of user for firebase notifications. It is required for firebase notifications.

  • payload.text: **** Text to be sent to user

  • payload.media.url: URL of image to be sent to user (In case of media messages)

  • payload.media.category: category of media Eg. IMAGE_URL. Available categories: IMAGE_URL, AUDIO_URL, VIDEO_URL, DOCUMENT_URL_

  • payload.media.caption: Caption to be sent with media file

This API will give you response in below format. If the api returns a succes response, it will include a message id in result.

{    
    "timestamp": "2022-08-04T11:51:51Z",    
    "status": 200,    
    "error": null,    
    "message": "Message sent.",    
    "path": "/message/send",    
    "result": {        
        "messageId": "2a03363a-7752-4a19-b7f7-e3a1e1423ae8"    
    }
}

Below are some curl requests for sending messages.

2. APIs

2.1 Netcore Whatsapp Message

  • Send text message to whatsapp number

    curl --location --request POST 'OUTBOUND:PORT/message/send' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "adapterId": "44a9df72-3d7a-4ece-94c5-98cf26307323",
        "to": {
            "userID": "97********",
            "deviceType": "PHONE"
        },
        "payload": {
            "text": "Hello there!"
        }
    }'
  • Send media message to whatsapp number

    curl --location --request POST 'OUTBOUND:PORT/message/send' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "adapterId": "44a9df72-3d7a-4ece-94c5-98cf26307323",
        "to": {
            "userID": "97********",
            "deviceType": "PHONE"
        },
        "payload": {
            "media": {
                "url": "@{IMAGE_PATH/URL}",
                "category": "IMAGE",
                "text": "Image Caption"
            }
        }
    }'

2.2 Gupshup Whatsapp Message

  • Send text message to whatsapp number

    curl --location --request POST 'OUTBOUND:PORT/message/send' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "adapterId": "44a9df72-3d7a-4ece-94c5-98cf26307324",
        "to": {
            "userID": "97********",
            "deviceType": "PHONE"
        },
        "payload": {
            "text": "Hello there!"
        }
    }'
  • Send media message to whatsapp number

    curl --location --request POST 'OUTBOUND:PORT/message/send' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "adapterId": "44a9df72-3d7a-4ece-94c5-98cf26307323",
        "to": {
            "userID": "97********",
            "deviceType": "PHONE"
        },
        "payload": {
            "media": {
                "url": "@{IMAGE_PATH/URL}",
                "category": "IMAGE",
                "text": "Image Caption"
            }
        }
    }'

2.3 Firebase Web Message

  • Send message to device

    The data field of the payload contains all the data that the backend might want to send to the user along with the message.

        curl --location --request POST 'http:/OUTBOUND:PORT/message/send' \
        --header 'Content-Type: application/json' \
        --data-raw '{
            "adapterId": "21f1d315-55cf-44e3-8355-4743d6519649",
            "to": {
                "userID": "97********",
                "deviceType": "PHONE"
            },
            "payload": {
                "text": "Testing",
                "data": [
                    {
                        "key": "fcmToken",
                        "value": "myFCMToken"
                    },
                    {
                        "key": "fcmClickActionUrl",
                        "value": "nipunlakshya://chatbot"
                    },
                    {
                        "key": "botDesc",
                        "value": "This is testing description"
                    },
                    {
                        "key": "botId",
                        "value": "This is testing bot id"
                    }
                ]
            }
        }'

Note: Param fcmClickActionUrl is being used to mention the url to open on click ot fcm notification. This url should have the same domain as the one on which the fcm tokens are registered, else the url will not work.

2.4 Gupshup SMS

  • Send message to phone

    curl --location --request POST 'OUTBOUND:PORT/message/send' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "adapterId": "64036edb-e763-44b1-99b8-37b6c7b292c5",
        "to": {
            "userID": "97********",
            "deviceType": "PHONE"
        },
        "payload": {
            "text": "Hi user"
        }
    }'

2.4 CDAC SMS

  • Send message to phone

    For sending message to phone number via CDAC, a templateId which is approved by CDAC is required and the payload text should have content of this template body.

    curl --location --request POST 'OUTBOUND:PORT/message/send' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "adapterId": "77164079-579a-4a70-b578-7dfe2afb677a",
        "to": {
            "userID": "97*********",
            "deviceType": "PHONE",
            "meta": {
                "templateId": "1007180838266527905"
            }
        },
        "payload": {
            "text": "Hi User"
        }
    }'
PreviousHistory APIsNextVault APIs

Last updated 1 year ago

Was this helpful?

🚀