V1 - Send Message

Send and receive messages, to single contacts per request, on channels connected to CosmoBots

This document is intended to be used for developers using CosmoBots API to send and receive messages, to single contacts per request, on channels connected to CosmoBots.

To send messages to registered channels we are considering you already have connected the channel to your Bot on CosmoBots.


Endpoint

POST https://api.cosmobots.io/messages/v1/send

Authentication

Every request needs to have these two parameters on the header. You may retrieve both on the Integration section of the platform. Follow these steps:

  • Login into the platform

  • Choose the Bot

  • On the left sidebar menu, choose Integrations, then API

  • Choose the Send Message API

  • Click on Enable API

  • Now you can copy both token and channelId to use on the requests

Sending Message

Here are the body fields used during this request. The format is JSON.

Contact Object

Session Object

Desk Object

Message Array [Object]

Message > Data (If Type is Text)

Message > Data (If Type is Buttons)

Message > Data (If Type is Cards)

Message > Data (If Type is Media)

Response Sync

Response Async

Examples Of Request

Sending Text Destination: Contact

POST https://api.cosmobots.io/messages/v1/send

{
    "destination": "contact",
        "contact": {
        "id": "5511999999999",
            "firtName": "Jerry",
                "phone": "5511999999999"
    },
    "message": [{
        "type": "text",
        "data": {
            "text": "Escreva Seu Texto Aqui"
        }
    }]
}

Sending Text With Buttons Destination: Contact

POST https://api.cosmobots.io/messages/v1/send

{
    "destination": "contact",
        "contact": {
        "id": "5511999999999",
            "phone": "5511999999999"
    },
    "message": [{
        "type": "buttons",
        "data": {
            "text": "Escreva Seu Texto Aqui",
            "buttons": [
                {
                    "title": "Botão 1",
                    "type": "text",
                    "value": "Botão 1"
                },
                {
                    "title": "Botão 2",
                    "type": "text",
                    "value": "Botão 2"
                }
            ]
        }
    }]
}

Sending Media Destination: Contact

POST https://api.cosmobots.io/messages/v1/send

{
    "destination": "contact",
        "contact": {
        "id": "5511999999999",
            "firstName": "Jerry",
                "phone": "5511999999999",
                    "custom": {
            "email": "test@test.com"
        }
    },
    "message": [{
        "type": "media",
        "data": {
            "type": "image",
            "name": "name_image",
            "url": "URL_Image",
            "mime_type": "image/png"
        }
    }]
}

Receiving Message

To receive messages coming from CosmoBots, you have to register your endpoint on our webhook. You may find the webhook setup on the Channels section of the platform. Follow these steps:

  • Login into the CosmoBots platform

  • Choose the Bot

  • On the left sidebar menu, choose Channel, then the specific channel you are using

  • On the Webhook Url field, include the endpoint that will receive the requests

The Body fields are the same as the fields from the Body of the Sending Message request above.

Last updated