Skip to content

Example Slash Command

Duda Nogueira edited this page Dec 14, 2022 · 11 revisions

Example Slash Command

relevant code

Author: Duda Nogueira

Objective: Create /example command with sub command pattern best practices showing how to send a Message or Notification at the same channel the command was run or a Direct Message to the user that has run the command.

Message Example

Run: /example message you should get

image

Notification Example

also, you can run: /example notification

image

Direct Example

as a third option, you can run: /example direct

demo-app-direct

What just hapenned?

Each installed app in Rocket.Chat will get it's own user, like on this example, demo-app.bot. If you don't set the sender of that notification or message, it will default to that user.

Some good practices

Of course, writing /example notification is not practical, and with time, you will want a shortcuts for that. So we added already some aliases and a help content to make it explicit. It is always a good practice to guide your user on how to use your command. If, for instance, the user try a non existent sub command, for example, /example asdasd this is what will happen:

image

Clone this wiki locally