Ep.5 Console Command | Supbot Whatsapp Chatbot API

in #utopian-io6 years ago

small banner.jpg

Repository

https://github.com/adsau59/supbot

What Will I Learn?

  • What is console command?
  • How to use core console commands?
  • How to create console command?

Requirements

Required Knowledge

  • Java

Resources for this Tutorial:

Difficulty

✔Basic
Intermediate
Advanced

Description

Outline and Overview

In this Supbot tutorial we will take a look on Console Commands.

What is Console Command?

During development, there could come a need to create custom code snippets that you want to execute during the execution of the bot, but writing it anywhere would disturb the Supbot's threads pipeline .

In in order to do the same, console commands can be used,

  • Console Commands are commands that can be entered in the console during the execution of the bot.
  • It is used to execute custom functions with or without arguments.
How to use Console Command?

After you execute the bot, whatsapp web will get initialized. After the initialization is done, a greater than sign will appear in the console (>), here you can enter your console command. First the command keyword has to be written, followed by its arguments, like keyword arg1 arg2.

In order to learn how to use console command, we will see the help & run command.

Help Command
  • help command is used to show the available commands that you can use and it also shows the usage of the target commands

  • just type help in the console without any arguments and hit enter to show a list of all the console commands available in the bot.

    help.PNG

  • If you want to check the usage of any command type help followed by keyword of the command you want to check the usage of.

  • for example, help quit

    help_quit.PNG

  • The usage shows the name of the command, its description, its template and an example of how to use it.

Run Command
  • run command is used to run feature commands, which is used by the clients in whatsapp, using console commands.

  • Using run command, Supbot creates a temporary client which has the highest privileges that is Role.SuperAdmin, which can run any command in any group even if it's feature is not added in the group, it is the only way to promote a Co-Admin to admin and demote Admin to Co-Admin.

    help_run.PNG

  • The first argument of the run command is the group ID of the group you want the run the command in, as I explained before, it creates a temporary client which will belong to this group..

  • Second argument is the command keyword, which shows which feature command to run, remember you don't have to use the command prefix (;;) here.

  • Third and the next arguments are the arguments for the feature command which has to be executed, if the feature command doesn't take any arguments you can leave this empty.

    Screenshot (6).png

  • The result of this command isn't displayed in the console, but it shows the result directly inside the whatsapp chat group.

How to create Console Command?

You can create your own console command to run any code snippet you want, in order to do that you have to,

quitcc.PNG

  1. Create a class and extend it with ConsoleCommand.
  2. Implement its abstract methods and constructor.
  3. Add the console command in the bot using Bot.getConsole().getConsoleCommandManager().add() method in the addThingsInBot() method in the main class.

Lets have a look at the constructor and all the abstract methods that you have to implement to create Console Command

Constructor

cc_constructor.PNG

  • Constructor of the ConsoleCommand takes 2 parameters, keyword and noOfArgs.
  • keyword is the string which is used to run the command.
  • noOfArgs is the number of arguments required to use the command, you can keep this value -1 in order to skip number of argument check for variable number of arguments.
Compute Method

cc_compute.PNG

  • compute(String[] args) method is the method which is executed when the command is entered in the console.
  • It contains one parameter, called args, it is a string array which contains the arguments passed from the console.
getHelper Method

cc_gethelper.PNG

  • getHelper() method is used to create usage helper which can be shown using help command.
  • It returns a helper object which has three string attributes,
    • Template, should contain the usage of the command,
    • Example, should contain an example of using the command,
    • Description, should contain an short description of the command.
What we will make?
  • In this episode we will create a broadcast console command.
  • It can be sued to send message to all the groups simultaneously with one command, it can be used to send updates like "Bot will go under maintenance in 10 mins".

By creating this console command, you will learn where console command is used, and how to make it so that during the development of your own features, you wont have to waste time making a work around for it.

Video Tutorial

Curriculum

Contact

If you have any problems or you want to contact me on DefineX Community discord server

Proof of Work Done

https://github.com/adsau59

Sort:  

Hi @adam-saudagar,

Thank you for your contribution to the video tutorial.

I can see that you have made some effort to improve on the delivery of the tutorial.

You can continue to work on making your tutorial more structural, especially when explaining the concepts taught so that it is easy for learners to follow.

This time I didn't hear any echo. Did you change the mic or you made some changes?

As instructional tutors, always be professional when you speak. Try to speak slower because most people with English as 2nd language tends to speak very fast.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks for the review @rosatravels, As I said in the reply for of your review in the previous post, I bought a new mic for making videos but didn't configured it correctly, hence the echo but now I think I did it correctly this time

Also, I am trying to speak slowly but it's tough, I tend to pause again and again while speaking so I have to edit it

And btw, can you please explain me how can I make the tutorials more structural?

Thank you for your review, @rosatravels! Keep up the good work!

Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 17 of all contributions awarded today. You can find the TOP DAILY TRUFFLE PICKS HERE.

I upvoted your contribution because to my mind your post is at least 6 SBD worth and should receive 80 votes. It's now up to the lovely Steemit community to make this come true.

I am TrufflePig, an Artificial Intelligence Bot that helps minnows and content curators using Machine Learning. If you are curious how I select content, you can find an explanation here!

Have a nice day and sincerely yours,
trufflepig
TrufflePig

Hi, @adam-saudagar!

You just got a 2.57% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hi @adam-saudagar!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @adam-saudagar!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @adam-saudagar! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!