Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Context

Context, which is passed to every handler.

Hierarchy

  • Context

Index

Constructors

constructor

  • new Context(api: API, eventType: string, object: object, message: string): Context
  • Parameters

    • api: API

      the API object

    • eventType: string

      the event type

    • object: object

      full object from Callback API

    • message: string

      the message

    Returns Context

Properties

Readonly api

api: API

API.

Private attachment

attachment: string[]

Attachments, which will be used in the reply

Private autoSend

autoSend: boolean = true

Does this Context's response need auto-sending?

Readonly eventType

eventType: string

Name of the event.

Private kbdObject

kbdObject: string

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

msg

msg: string

Incoming user message.

Note: If Core.cmd handler, contains message without cmd_prefix and the command

Readonly obj

obj: any

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.

Private pid

pid: string

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 can be obtained using getOriginalPid.

Private replyText

replyText: string

Text, which will be used in the reply

Methods

attach

  • attach(type: string, ownerId: string | number, resId: string | number, accessKey?: string): void
  • Adds an attachment to the message.

    Note: More information on the parameters can be found in VK API docs.

    Parameters

    • type: string

      the type of attachment

    • ownerId: string | number

      resource owner ID

    • resId: string | number

      resource ID

    • Optional accessKey: string

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

    Returns void

clear

  • clear(): void
  • Clears the buffer and resets the Peer ID back to original.

    For example, after calling this you can compose another message to the same user.

    Returns void

getOriginalPid

  • getOriginalPid(): string
  • Returns the original peer ID from the Callback API object.

    Returns string

getPid

  • getPid(): string

keyboard

  • Attaches a keyboard.

    example
    const { Color, Keyboard, button } = vk.kbd;
    
    core.cmd('keyboard', $ => {
        // Set 'true' instead of 'false' to make it disappear after a button was pressed
        var kbd = new Keyboard([
            // Rows
            [
                button.text('Default'),
                button.text('Primary', Color.Primary),
                button.text('Negative', Color.Negative),
                button.text('Positive', Color.Positive)
            ],
            [
                button.text('Maximum rows is 10, columns - 4.')
            ],
       ], false);
    
       $.text('Here is your keyboard, as promised.');
       $.keyboard(kbd);
    }, 'demo keyboard');

    Parameters

    Returns void

needsAutoSend

  • needsAutoSend(): boolean

noAutoSend

  • noAutoSend(): void
  • Prevents this handler from sending the message automatically after it finishes.

    Returns void

removeKeyboard

  • removeKeyboard(): void

send

  • send(): Promise<void>
  • Sends the composed message to user. Note: After the handler finishes its work, this method is called automatically (if noAutoSend was not called)

    Returns Promise<void>

setPid

  • setPid(pid: string | number): void
  • Sets a new peer ID.

    Parameters

    • pid: string | number

      new peer ID

    Returns void

text

  • text(txt: string): void
  • Sets the reply message text.

    Parameters

    • txt: string

      new text

    Returns void

Generated using TypeDoc