adam-saudagar avatar

Ep.2 Commands & Feature | Supbot Whatsapp Chatbot API

adam-saudagar

Published: 30 May 2018 › Updated: 30 May 2018Ep.2 Commands & Feature | Supbot Whatsapp Chatbot API

Ep.2 Commands & Feature | Supbot Whatsapp Chatbot API

Repository

https://github.com/adsau59/supbot

What Will I Learn?

  • What is Command in Supbot API?
  • What is Feature in Supbot API?
  • How to create Command using Supbot API?

Requirements

Required Knowledge

  • Java

Difficulty

Basic
✔Intermediate
Advanced

Description

In this Supbot API tutorial, we will understand what is Command and Feature and why it is used. We will then create a custom command that shows meaning of a term using Urban Dictionary REST API.

Commands

Commands are the functions that can be called by a client. So, the clients can use command to tell the bot what to do. When a client writes a command in a group, Supbot reads the command and performs actions depending on the command client used, arguments the client passed, and the client themself.

To create a command, create a class and extend it with Command class and then implement its abstract methods and override its Constructor.

command_constructor_definition.PNG


Example:
solve_constructor.PNG

When a command is called, the compute method is called.

compute_prototype.PNG


Example:
register_compute_definition.PNG

getHelper method is used when the client uses help commands, which explains them how the command should work.

Example:
gethelper_definition_ud.PNG

Features

Feature encapsulates many commands into one group. For example, if we want to make voting in our bot, there will be commands like, start-vote, vote, end-vote, show-vote-results so we can group all these commands into one group called Voting.

To create a feature, create a class and extend it with Feature calss and then implement its abstract methods and override its Constructor.

feature_constructor_definition.PNG


Example:
account_feature_constructor_definition.PNG

getDescription simply returns a string which says what is the purpose of the feature, it is shown when the help-feature command is used.

getdescription_prototype.PNG


Example:
account_getdescription_definition.PNG

How to add it in the Supbot?

So to add your own command to the bot, you will have to first Create the Command
Then Create the feature, and put the command in its constructor parameter
Then finally add the feature to the bot, using Bot.getFeatureManager().add() function, in the addThingsInBot method in the main class

Example:
botaddfeature.PNG

Sources for this Tutorial:

Video Tutorial

Curriculum

Proof of Work Done

https://github.com/adsau59

Leave Ep.2 Commands & Feature | Supbot Whatsapp Chatbot API to:

Written by

Game Developer, Gamer, Otaku :D

Read more #utopian-io posts


Best Posts From adam-saudagar

We have not curated any of adam-saudagar's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From adam-saudagar