Skip to content

Example Slash Command

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

About

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.

Author: Duda Nogueira

relevant code

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 have just happened?

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.

Be aware that, in order to our demo-app.bot send a message to a room, it must be added to that room first.

We have executed the /example with a first argument. This argument defines what the app needs to do. Also, if you run the command without any argument, it will notice that and return the same content of the help sub command.

Good practices

Of course, writing /example notification is not practical, and with time, you will want a shortcut 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

When creating commands, consider that not everybody like the /slashcommand.

And that's ok 😃

We can register an Action Button on certain contexts of Rocket.Chat (a room or message, for example) and open a Modal or Contextual bar with some interface elements.

Clone this wiki locally