Interacting

Note: Use at your own discretion. Do not spam people with this.

This page will guide you through how to define and organize commands in your application.

Creating Commands

There are multiple ways of responding to a message. The most common way of sending a reply is by returning it in your controller method. This method acknowledges the interaction and sends a new message in response.

1@Controller()
2export class AppController {
3  @Command('ping')
4  ping() {
5    return 'Pong!';
6  }
7}

See how to create Dynamic Commands.

Good to know: remoteJid must be in format +19999999999@s.whatsapp.net, for groups must be 123456789-123345@g.us.

Sending media

Sending media (video, stickers, images) is easier & more efficient than ever.

  • You can specify a buffer, a local url or even a remote url.
  • When specifying a media url, we never loads the entire buffer into memory; it even encrypts the media as a readable stream.
  • To learn more about stickers, read this page.
1return {
2  image: { url: './cat.jpeg' },
3  caption: "Look this cat",
4}

Reading messages

A set of message keys must be explicitly marked read now. In multi-device, you cannot mark an entire "chat" read as it were. This means you have to keep track of unread messages.

1const key = {
2  id: 'AHASHH123123AHGA',
3  remoteJid: '1234-123@g.us',
4  participant: '912121232@s.whatsapp.net'
5}
6

7// You can pass multiple keys to read multiple messages
8await sock.readMessages([key])