Send Messages

Learn how to send messages with Unipile

Feature available for : LinkedIn, WhatsApp, Instagram, Messenger, Telegram

Send a message in an existing Chat / Group

Use the POST chats/{chat_id}/messages Method or use the appropriate SDK Method, to send a message by providing a chat_id you can find by retrieving chats lists, or when receiving a message to automate replies on Webhook trigger.

curl --request POST \
     --url https://{YOUR_DSN}/api/v1/chats/9f9uio56sopa456s/messages \
     --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
     --header 'accept: application/json' \
     --header 'content-type: multipart/form-data' \
     --form 'text=Hello world !'
const response = await client.messaging.sendMessage({
  chat_id: "9f9uio56sopa456s",
  text: "Hello world !"
})

📘

If you want to send a message into an existing chat using an attendee identifier, you can read the next section, but if you have the choice, always prefer the usage of chat_id.


Send a message to a User

There is two cases where you want to send a message to a User instead of in a Chat:

  • You don't have access to the id of the existing chat
  • The connected account does not have a conversation history this specific user, so there is no existing chat and you must start a new chat.

To send a message to a User, use the POST /chats Method or the appropriate SDK Method.

In the account_id field, provide the ID of the connected account to send the message from. In the attendees_ids field, give one user's Provider internal ID. Please refer to those guides if you need more informations about Users and how their IDs work.

The method will send a message in a 1 to 1 chat, and:

  • If the chat does not exist, it will be created, synced, and returned
  • If the user was not an attendee yet, it will be synced
curl --request POST \
     --url https://{YOUR_DSN}/api/v1/chats \
     --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
     --header 'accept: application/json' \
     --header 'content-type: multipart/form-data' \
     --form account_id=Yk08cDzzdsqs9_8ds \
     --form 'text=Hello world !' \
     --form attendees_ids=j08dsqQS89QSD \
const response = await client.messaging.startNewChat({
  account_id: 'Yk08cDzzdsqs9_8ds',
  text: 'Hello world !',
  attendees_ids: ["ACoqsqssj08dsqQS89QSD"],
})

LinkedIn specific use cases

With Linkedin, unless InMail, you can start new chats only with your Relations. You can use Unipile to invite people to be in your Relations : Send a contact invitation

If you have a Premium LinkedIn account and want to send InMails, set the inmail property to true in the payload. You have to consider the account type of user (with /me route or GET account) to use to good API (classic/recruiter/sales_navigator)

curl --request POST \
     --url https://{YOUR_DSN}/api/v1/chats \
     --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
     --header 'accept: application/json' \
     --header 'content-type: multipart/form-data' \
     --form account_id=ACoqsqsqdsqdsdqsdssj08dsqQS89QSD \
     --form 'text=Hello world !' \
     --form attendees_ids=j08dsqQS89QSD \
     --form linkedin[api]=classic \
     --form linkedin[inmail]=true \
const response = await client.messaging.startNewChat({
  account_id: 'Yk08cDzzdsqs9_8ds',
  text: 'Hello world !',
  attendees_ids: ["ACoqsqsqdsqdsdqsdssj08dsqQS89QSD"],
  options: {
    linkedin: {
      api: 'classic',
      inmail: true
    }
  }
})

Send attachments

You can provide an additional attachment to the request body to send attachments along your text message.


Create a group chat

To start a new group chat, use the POST /chats Method or the appropriate SDK Method and provider a list of user's Provider internal ID in attendees_ids along an optional title for the group name.

Please refer to those guides if you need more informations about Users and how their IDs work.

The chat and its group participants will be synced.

curl --request POST \
     --url https://{YOUR_DSN}/api/v1/chats \
     --header 'X-API-KEY: {YOUR_ACCESS_TOKEN}' \
     --header 'accept: application/json' \
     --header 'content-type: multipart/form-data' \
     --form account_id=k08cds98ds \
     --form 'text=Hello world !' \
     --form attendees_ids=j08dsqQS89QSD \
     --form attendees_ids=587Dsbcqs75QS \
     --form title=Vacation