POST graph.user.messages
Create new messages, modify chats, dialogs and their participants
Content-Type: application/json;charset=utf-8 header should be specified for all Graph API POST requests
This method allows you to do following actions:
- create new chat messages;
- modify chat / dialog state;
- chat participants management;
- notify other chat participants about your actions and state.
Request example
?access_token=tkn18YdUJZe:CQABPOJKAKEKEKEKE
Actions over chat state
You can edit following chat data:
- chat title;
- chat logo.
Example request to edit chat title:
Example request to edit chat icon:
Participants management
Following actions can be done with / or by chat participants:
- add new chat participant;
- remove chat participant;
- leave chat by current user
Example request to add new chat participant:
Example request to remove chat participant:
Example request to leave chat by user:
Sending messages
This is a key feature of this method.
To create a new message you need to send a POST-payload data with a message object which is similar to an object that you can get with me/messages/get method.
Text message example:
Sending messages with attachments
A message with image and file attachments can be sent. Maximum number of attachments is 5.
A message with an IMAGE attachment can be sent like this:
A message with a FILE attachment can be sent like this:
More info about file uploading can be found here - graph.user.fileUploadUrl
Current user state
Current user can inform other chat participant about some of his actions or his state:
- mark all messages as seen - mark_seen;
- user us typing a new message - typing_on;
- user is sending new file (video, audio, image) - sending_photo.
Example request:
Direct user messages
It is possible to send a message from group to a single or multiple users at once.
User must allow to receive group messages before it can be sent to him.
Following message syntax is used for this purpose:
Each user from the list will get a message in his own group-to-user chat.
API will respond with two corresponding list of values: * boolean type values list that indicate if message was or was not successfully sent; * list of user-to-group chat ids in which messages where sent.
To send a message directly to one user you can use a simplified message syntax:
Message format
Attachments
Message can contain a single or multiple attachments of following type:
- IMAGE - image;
- VIDEO - video;
- AUDIO - audio;
- SHARE - OK content reshare;
- FILE - file of any extension;
- CONTACT - user contact;
- INLINE_KEYBOARD - action buttons structure;
- LOCATION - user location;
- MUSIC - OK music track;
- CALL - information about video / audio call;
- PRESENT - OK present;
- STICKER - OK sticker.
Attachment’s payload depends on its type and can differ.
IMAGE
The image attachment.
There are following ways to send such attachment to a chat:
- specify token from existing message with attachment
- specify token, acquired during image upload using method GET graph.user.fileUploadUrl method
- specify image URL, but only 1 such image can be present in request
VIDEO
The video attachment.
There are following ways to send such attachment to a chat:
- specify token from existing message with attachment
- specify token, acquired during video upload using method GET graph.user.fileUploadUrl method
AUDIO
The audio attachment.
There are following ways to send such attachment to a chat:
- specify token from existing message with attachment
- specify token, acquired during audio upload using method GET graph.user.fileUploadUrl method
FILE
File of any format.
There are following ways to send such attachment to a chat:
- specify token from existing message with attachment
- specify token, acquired during audio upload using method GET graph.user.fileUploadUrl method
SHARE
Reshare of a content previously published on OK. This attachment can contain a link to a group, video, group / user topic, image, etc.
Creation of this type of attachment via botapi is not supported.
CONTACT
OK’s user contact.
There are following ways to send such attachment to a chat:
- specify user identifier
- specify vCard electronic business card data
LOCATION
User’s location.
There are following ways to send such attachment to a chat:
- specify coordinates latitude and longitude (other fields are optional)
MUSIC
OK music track.
There are following ways to send such attachment to a chat:
- specify track identifier
CALL
Video/audio call info.
Creation of this type of attachment via botapi is not supported.
PRESENT
This type of attachment is currently not supported
OK present.
Creation of this type of attachment via botapi is not supported.
STICKER
OK sticker.
There are following ways to send such attachment to a chat:
- specify sticker identifier
INLINE_KEYBOARD
REQUEST_GEO_LOCATION and REQUEST_CONTACT type buttons are currently not supported
Buttons structure.
Buttons list is a two dimensional array where buttons can be placed one on a single line or as a group.
There are following buttons types supported:
- CALLBACK - main type of a button. When pressed by a user a new message is sent to a chat (called callback message);
- LINK - a button that contains a link to another URL;
- REQUEST_CONTACT - request of current user’s contact info;
- REQUEST_GEO_LOCATION - request of current user’s location info.