> For the complete documentation index, see [llms.txt](https://uci.sunbird.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://uci.sunbird.org/use/developer/api-documentation/direct-message-apis.md).

# 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"
      }
  }'
  ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://uci.sunbird.org/use/developer/api-documentation/direct-message-apis.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
