Import multiple messages into Tiledesk using REST APIs from third party app

This tutorial explains how to insert multiple messages into Tiledesk using the REST API from a third-party app. Example use case: you have a chatbot or customer support system that serves users automatically, but at some point you want to forward the chat to Tiledesk so agents handle the request.

Steps

1

Signup a user on Tiledesk

To use Tiledesk APIs you must sign up on the beta environment:

https://panel.tiledesk.com/v3/dashboard

After signup follow the wizard to create your first Tiledesk project.

Get the PROJECT_ID of the created project under Project Settings — you will use this later.

2

Anonymous end-user authentication through APIs

Authenticate end-users using the Anonymous authentication REST API: https://developer.tiledesk.com/apis/rest-api/authentication#anonymous-authentication-for-a-user

Example request:

signinAnonymously
curl -v -X POST -H 'Content-Type:application/json' \
-d '{"id_project":"5e2c35c8f0dbc10017bb3aac", "firstname":"John"}' \
https://api.tiledesk.com/v3/auth/signinAnonymously

Example response (returns a JWT token and the created user id):

{
   "success":true,
   "token":"JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.XYZ....",
   "user":{
      "_id":"fc43a0e1-ba85-404e-9a44-bf0050330898",
      "firstname":"John",
      "id":"fc43a0e1-ba85-404e-9a44-bf0050330898",
      "fullName":"John"
   }
}

You will use the returned user id (requester) when creating the conversation.

3

Creating the conversation (request)

Use the Create a conversation (request) REST API: https://developer.tiledesk.com/apis/rest-api/requests#create-a-request

Main parameters to set:

  • YOUR_ADMIN_EMAIL and PASSWORD: use your admin credentials

  • SENDER: the anonymous user id created in the previous step

  • FIRST_MESSAGE: text used to summarize the conversation subject (usually the first message from the requester)

  • PROJECT_ID: your project id

Example request:

create request
curl -v -X POST -H 'Content-Type:application/json' \
-u YOUR_ADMIN_EMAIL:PASSWORD -d '{"sender":"SENDER", "first_text":"FIRST_MESSAGE"}' \
https://api.tiledesk.com/v3/PROJECT_ID/requests/

Concrete example:

curl -v -X POST -H 'Content-Type:application/json' \
-u [email protected]:xyz \
-d '{"sender":"fc43a0e1-ba85-404e-9a44-bf0050330898", "first_text":"How can i restore my password"}' \
https://api.tiledesk.com/v3/5e2c35c8f0dbc10017bb3aac/requests/

Example response (note the request_id field):

{
   "_id":"6346cbed38c343d545cf8092",
   "request_id":"support-group-5e2c35c8f0dbc10017bb3aac-8e40526e6dfb4450a572cd4ede01f464",
   ....
}

An empty conversation (without messages) is created. Keep the request_id value — you will need it to insert messages.

4

Sending messages to a conversation

Use the Insert multiple messages REST API to import messages: https://developer.tiledesk.com/apis/rest-api/messages#insert-multiple-messages

Required parameters:

  • request_id: the unique request identifier generated by the previous call

  • the admin credentials

  • an array of message objects where each object includes:

    • text: the message text

    • sender: the user identifier of the sender

    • attributes.clienttimestamp: use this property to force the message timestamp in milliseconds

Example request:

insert multiple messages
curl -v -X POST -H 'Content-Type:application/json' \
 -u YOUR_ADMIN_EMAIL:PASSWORD \
 -d '[{"sender":"bb0d809b-b093-419b-8b48-11a192cc3619","text":"How can i restore my password", "attributes":{"clienttimestamp":1665584701710}},{"sender":"chatbot1", "text":"You can find it here https://tiledesk.com", "attributes":{"clienttimestamp":1665584701711}}]'  \
 https://api.tiledesk.com/v3/5e2c35c8f0dbc10017bb3aac/requests/support-group-5e2c35c8f0dbc10017bb3aac-8e40526e6dfb4450a572cd4ede01f464/messages/multi

After the import, the conversation will appear in your project's Requests panel. Requests are updated in real time; if default settings are unchanged the request will be assigned to you (make sure your agent status is "available").

The agent can then open the conversation in the agent chat panel.

Images

Signup wizard screenshot
Project settings screenshot

Feedback

Do you have feedback on this article? Send your feedback by email to [email protected]

  • Sending and receiving messages with Tiledesk APIs: https://developer.tiledesk.com/apis/tutorials/rest-api/sending-and-receiving-messages

  • Webhooks: https://developer.tiledesk.com/apis/tutorials/webhooks

Last updated: 2 years ago

Privacy: By browsing this site you accept the privacy policy: https://tiledesk.com/privacy.html