POST graph.chat.answer

Answer to a user after he pressed a CALLBACK-type button

Внимание! POST-запросы должны выполняться с заголовком Content-Type: application/json;charset=utf-8

This method allows you to respond to a user after he pressed a CALLBACK-type button in a previous message.

This method takes a single parameter:

NameTypeRequiredDescription
callbackIdStringYescallback identifier

Request example

https://api.ok.ru/graph/chat:C3ecb9d02a600/answer
   ?access_token=tkn18YdUJZe:CQABPOJKAKEKEKEKE
   &callbackId=someCallbackId

Request body

In a request body a message must be present.

Message format

{
  "message": {
    "text": "String", /* Message text */
    "attachment": { 
      "type": "IMAGE|VIDEO|AUDIO|SHARE|FILE|CONTACT|INLINE_KEYBOARD|LOCATION|MUSIC|CALL|PRESENT|STICKER", /* attachment type */
      "payload": AttachmentPayload /* attachment body, depends on type */
    }, /* single message attachment */
    "attachments": [{
      "type": "IMAGE|VIDEO|AUDIO|SHARE|FILE|CONTACT|INLINE_KEYBOARD|LOCATION|MUSIC|CALL|PRESENT|STICKER",
      "payload": AttachmentPayload
    }], /* multiple message attachments */
    "privacyWarning": "SCREENSHOT|SCREENCAST",
    "reply_to": "MID:" /* responded message id */
  }
}

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.

    
{
  "id": "imageId",
  "token": "imageToken",
  "url": "https://image.url"
}

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
{
  "token": "imageToken"
}
  • specify image URL, but only 1 such image can be present in request
{
  "url": "https://image.url"
}

VIDEO

The video attachment.

{
  "id": "videoId",
  "token": "videoToken",
  "url": "https://video.url"
}

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
{
  "token": "videoToken"
}

AUDIO

The audio attachment.

{
  "id": "audioId",
  "token": "audioToken",
  "url": "https://audio.url"
}

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
{
  "token": "audioToken"
}

FILE

File of any format.

{
  "id": "fileId",
  "token": "fileToken",
  "url": "https://file.url"
}

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
{
  "token": "fileToken"
}

SHARE

Reshare of a content previously published on OK. This attachment can contain a link to a group, video, group / user topic, image, etc.

{
  "id": "123456789",                                        
  "url": "https://ok.ru/group123456789/topic/123456789"
}

Creation of this type of attachment via botapi is not supported.

CONTACT

OK’s user contact.

{
  "id": "123456789",                /* user identifier */
  "name": "firstName lastName",     /* username */
  "photoUrl": "https://photo.url",  /* link to user's avatar */
  "phone": "79493344555",           /* user phone number */
  "vcfBody": "..."                  /* vCard electronic business card */
}

There are following ways to send such attachment to a chat:

  • specify user identifier
{
  "id": "123456789"
}
  • specify vCard electronic business card data
{
  "vcfBody": "..."
}

LOCATION

User’s location.

{
  "latitude": 59.928658,
  "longitude": 30.38113,
  "altitude": 1.0000,
  "epu": 1.0000,
  "heading": 1.0000,
  "speed": 1.0000,
  "zoom": 1.0000,
  "livePeriod": 600  /* time during which the user will share the live location, in seconds */
}

There are following ways to send such attachment to a chat:

  • specify coordinates latitude and longitude (other fields are optional)
{
  "latitude": 59.928658,
  "longitude": 30.38113
}

MUSIC

OK music track.

{
  "id": "23486020457601",                           
  "url": "https://ok.ru/music/track/23486020457601" 
}

There are following ways to send such attachment to a chat:

  • specify track identifier
{
  "id": "23486020457601",                           
}

CALL

Video/audio call info.

{
  "id": "23486020457601",                           /* call identifier */
  "type": "AUDIO|VIDEO",                            /* call type */
  "hangupType": "CANCELED|REJECTED|HUNGUP|MISSED"   /* call hangup type */
  "duration": 10                                    /* call duration */
}

Creation of this type of attachment via botapi is not supported.

PRESENT

This type of attachment is currently not supported

OK present.

{
  "id": "23486020457601",            /* present identifier */
  "status": "SENT",                  /* present status */
  "receiverId": "USER:12345678901",  /* receiver id */
  "senderId": "USER:12345678902"     /* sender id */
}

Creation of this type of attachment via botapi is not supported.

STICKER

OK sticker.

{
  "id": "c23a918ef4",                                         
  "url": "https://i.mycdn.me/getSmile?smileId=c23a918ef4"     
}

There are following ways to send such attachment to a chat:

  • specify sticker identifier
{
  "id": "c23a918ef4"                                         
}

INLINE_KEYBOARD

REQUEST_GEO_LOCATION and REQUEST_CONTACT type buttons are currently not supported

Buttons structure.

{
    "keyboard": {
        "buttons": [
            [
                {
                    "type": "CALLBACK",                     /* button type */
                    "text": "someText",                     /* button text */
                    "intent": "DEFAULT|POSITIVE|NEGATIVE",  /* button color scheme */
                    "payload": "callbackPayload"            /* payload text */
                }
            ],
            [
                {
                    "type": "LINK",
                    "text": "someText",
                    "intent": "DEFAULT|POSITIVE|NEGATIVE",
                    "url": "https://some.url"               
                }
            ],
            [
                {
                    "type": "REQUEST_CONTACT",
                    "text": "someText",
                    "intent": "DEFAULT|POSITIVE|NEGATIVE"
                },
                {
                    "type": "REQUEST_GEO_LOCATION",
                    "text": "someText",
                    "intent": "DEFAULT|POSITIVE|NEGATIVE",
                    "quick": true
                }
            ]
        ]

    },
    "callbackId": "16ef50d9a4e00c516ef50d9a4e00c516ef50d9a4e00c5"   /* callback identifier */
}

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.

Response example

{
  "success": true
}