Context

Context

Context, which is passed to every handler

Constructor

new Context(api, eventType, object, message) → {Context}

Source:
Parameters:
Name Type Description
api API

the API object

eventType string

the event type

object Object

full object from Callback API

message string

the message

Returns:
Type:
Context

Members

(private, static) this._attachment :string

Attachment, which will be used in the reply

Source:
Type:
  • string

(private, static) this._kbdObject :Object

Object of the Keyboard, which will be used in the reply

Source:
Type:
  • Object

(private, static) this._pid :string|number

The ID of a peer, to which the reply is going to be sent

Note: You can change this using setPid() method, the original Peer ID is available in $.obj.peer_id

Source:
Type:
  • string | number

(private, static) this._replyText :string

Text, which will be used in the reply

Source:
Type:
  • string

(static) this.api :API

API

Source:
Type:

(static, readonly) this.autoSend :boolean

Does this Context's response need auto-sending?

Source:
See:
Type:
  • boolean

(static) this.eventType :string

Name of the event

Source:
Type:
  • string

(static) this.msg :string

Incoming user message Note: If cmd() handler, contains message without cmd_prefix and the command

Source:
Type:
  • string

(static) this.obj :Object

Full object passed by Callback API

Note: If message_new, message_reply, message_edit or no_match event, this is a Private message object. Else, see Callback API docs or Groups Events docs for more information.

Source:
Type:
  • Object

Methods

attach(type, ownerId, resId, accessKeyopt)

Adds an attachment to the message Note: More information on the parameters can be found in VK API docs

Source:
Parameters:
Name Type Attributes Description
type string

the type of attachment

ownerId string | number

resource owner ID

resId string | number

resource ID

accessKey string <optional>

resource access key, if needed; see Access Key page in API docs for more information

clear()

Clears the buffer and resets the User ID back to original For example, after calling this you can compose another message to the same user

Source:

keyboard(kbd)

Attaches a keyboard

Source:
Parameters:
Name Type Description
kbd Keyboard

the keyboard

Example
var Keyboard = vk.kbd.Keyboard
var Button = vk.kbd.Button
var colors = vk.kbd.colors

core.cmd('keyboard', $ => {
    // Set 'true' instead of 'false' to make it disappear after a button was pressed
    var kbd = new Keyboard([
        // Rows
        [
            new Button('Default'),
            new Button('Primary', colors.primary),
            new Button('Negative', colors.negative),
            new Button('Positive', colors.positive)
        ],
        [
            new Button('Maximum rows is 10, columns - 4.')
        ],
   ], false)

   $.text('Here is your keyboard, as promised.')
   $.keyboard(kbd)
}, 'demo keyboard')

noAutoSend()

Prevents this handler from sending the message automatically after it finishes

Source:

removeKeyboard()

Attaches an empty keyboard

Source:

(async) send()

Sends the composed message to user Note: After the handler finishes its work, this method is called automatically (if noAutoSend was not called)

Source:

setPid(pid)

Sets a new peer ID

Source:
Parameters:
Name Type Description
pid string | number

new peer ID

text(txt)

Sets the reply message text

Source:
Parameters:
Name Type Description
txt string

new text