Skip to main content

Document Message

Document Message type allows you to send documents, images, video or audio files from your applications.

This api will get base64 encoded string of your file nd it will send it to your Diyalog clients. Platfrom will permit only smaller than 5MB size of files. Otherwise you will receive error from the api.

This api is also asynchronous and when a api call received the system only check api token, recepient, file data, file size and than return success as response. After that api will try to send the document to you clients asynchronously. If you want to sure the file is sent or not, you should check the webhook events that feed to your webhook api by Diyalog.

Request URI#

https://<DIYALOG-SERVER-API-ENDPOINT>/v1/bots/sendmessage/<YOUR-BOT-ACCESS-TOKEN>

Example Request#

curl -X POST -H "Content-Type: application/json" -d '{
"recipient": {
"appCustomerId": "70023"
},
"message": {
"messageId":"messageId-5566112",
"document" : {
"fileName" : "diyalog-s3.pdf",
"fileData" : "JVBERi0xLjcKJYGBgYEKCj....",
"mimeType" : "pdf",
},
"quickReplies" : [],
"quickRepliesV2" : []
}
}' "https://<DIYALOG-SERVER-API-ENDPOINT>/v1/bots/sendmessage/<YOUR-BOT-ACCESS-TOKEN>"

Request Details#

recipient#

You can pass the user information you want to send the message to api in the recipient object.

PropertyTypeDescriptionMandatory
appCustomerIdStringCustomer id in your systemOptional
appStaffIdStringYour staff id.Optional
idStringUnique DLG user id.Optional

You can pass the the user information that will receive your message with this object. Your request should only have one of the properties that appCustomerId, appStaffId or id.

There are two unique id for a single user in the DLG platform One of them is DLG user id. This id is created randomly when user registering to the system. Besides of this id, according to the user type, one of the customer id or staff id are stored for the user in DLG.

As a result, you can use one of the customer id or staff id and DLG id in order to send message.

If you know the DLG user id, you can use it for customor or staff.

Using customer id and staff id is more applicable than using DLG user id. Because if you want to use DLG id, you should store all DLG user ids in your system.

message#

PropertyTypeDescriptionMandatory
messageIdStringThis is a unique id of your message. You should create it in your system and send it to api. If you don't create and sent it to api DLG will create it for you and send it to you in the response of your request. DLG platfrom will feed the events of the messages to your system by this id. You can use it to differenciate events by this id. Therefore, this id is important for following all events of your message by your system.Optional
documentObjectdocument object that has content of the document.Yes
quickRepliesArray<quickReply>It should be set as empty array. ("quickReplies" : [])Yes
quickRepliesV2Array<quickReplyV2>It should be set as empty array. ("quickRepliesV2" : [])Yes

document#

document object contains data of your document that you want to sent to your clients.

PropertyTypeDescriptionMandatory
fileNameStringIt is the filename of the document with file extention.Yes
fileDataStringBase64 encoded string of bytes of the file.Yes
mimeTypeStringThis is the type of your file. You can add extention of your file.No
photoObjectIf you are sending an image file and you want to show thumbnail in clients, you can provide photo object that has detail of the image file. If you are sending an image and you give this object, Diyalog will automatically create a thumbnail of the file and make this thumbnail appear in the messaging screens even if the user does not open the image in the client.No
videoObjectIf you are sendinding a video file, you can provide video object that has some detail of the video file. If provide this object, Diyalog will show this file as video message format other than standart document.No
voiceObjectIf you are sendinding a voice message file, you can provide voice object that has some detail of the voice file. If provide this object, Diyalog will show this file as voice message format other than standart document.No
Important Note :

In order for the system to work properly, you must give only one of the photo, video and voice objects as a parameter. Otherwise, you may send an incorrect message. If you do not provide any of these objects, the system will transmit the document as a standard document message.

photo#

photo object contains width and height information of your image

PropertyTypeDescriptionMandatory
widthIntegerWidth of your image.Yes
heightIntegerHeight of your image.Yes

Example Request#

curl -X POST -H "Content-Type: application/json" -d '{
"recipient": {
"appCustomerId": "70023"
},
"message": {
"messageId":"messageId-5566112",
"document" : {
"fileName" : "background_test_1_landscape.jpg",
"fileData" : "JVBERi0xLjcKJYGBgYEKCj....",
"mimeType" : "pdf",
"mimeType" : "jpg",
"photo" : {
"width" : 640,
"height" : 480
}
},
"quickReplies" : [],
"quickRepliesV2" : []
}
}' "https://<DIYALOG-SERVER-API-ENDPOINT>/v1/bots/sendmessage/<YOUR-BOT-ACCESS-TOKEN>"

video#

video object contains width, height and duration information of your video

PropertyTypeDescriptionMandatory
widthIntegerWidth of your video.Yes
heightIntegerHeight of your video.Yes
durationIntegerDuration in seconds of your video.Yes

Example Request#

curl -X POST -H "Content-Type: application/json" -d '{
"recipient": {
"appCustomerId": "70023"
},
"message": {
"messageId":"messageId-5566112",
"document" : {
"fileName" : "capture_1.mp4",
"fileData" : "JVBERi0xLjcKJYGBgYEKCj....",
"mimeType" : "pdf",
"mimeType" : "mp4",
"video" : {
"width" : 360,
"height" : 480,
"duration": 120
}
},
"quickReplies" : [],
"quickRepliesV2" : []
}
}' "https://<DIYALOG-SERVER-API-ENDPOINT>/v1/bots/sendmessage/<YOUR-BOT-ACCESS-TOKEN>"

voice#

voice object contains duration information of your video

PropertyTypeDescriptionMandatory
durationIntegerDuration in seconds of your voice message.Yes

Example Request#

curl -X POST -H "Content-Type: application/json" -d '{
"recipient": {
"appCustomerId": "70023"
},
"message": {
"messageId":"messageId-5566112",
"document" : {
"fileName" : "voice.ogg",
"fileData" : "JVBERi0xLjcKJYGBgYEKCj....",
"mimeType" : "pdf",
"mimeType" : "ogg",
"voice" : {
"duration": 18
}
},
"quickReplies" : [],
"quickRepliesV2" : []
}
}' "https://<DIYALOG-SERVER-API-ENDPOINT>/v1/bots/sendmessage/<YOUR-BOT-ACCESS-TOKEN>"

Response#

Successful API requests return the json object with the answer code http-2XX.

Sample response

{
"recipient_id": "2074022437",
"message_id": "-7523925115459309081"
}

Error Responses#

Http Status CodeError MessageDescription
400
The request content was malformed: ....Requset is invalid Malformed api request.
400
Exceeded max file size of 5MBDocument is too big to send. It should be smaller than 5MB
400
File data bytes not validBase 64 encoded file bytes cannot be parsed. File data is not valid.
400
File data bytes is emptyFileData is empty. You should provide valid fileData to the api
400
File as photo cannot be parsed due to it is not a image file.Document sent as photo is not have valid image file.
503
You may be using wrong token.Your Diyalog webbot token is not validated. Check your token
500
Not delivered due to recepient not found.Message cannot be sent due to receipient is not found in Diyalog
500
Sender bot is not alive.Diyalog Internal server error. WDiyalog webbot is not active in the server to send message.