Supbot API | Whatsapp Group Chatbot API | Developement update #2

in #utopian-io6 years ago (edited)


supbot banner

It has been 3 months since the last development update, as I was pretty busy with other projects and making video tutorials for this one and also I was looking for a big update change (Commit3) for the update blog. I have included the previous two commits too as those commit happened after the previous development update.

Repository

https://github.com/adsau59/supbot
Commit1
Commit2
Commit3

What is Supbot API?

Supbot API is a Whatsapp Group Chatbot API, Showcase video.

Whatsapp is the most used messenger platform, but the lack of bot support made it very tedious to perform some operations that other platform with bot support performs easily.

Supbot API uses Selenium to automate Whatsapp Web to read and collect data, runs business logic and perform different actions defined by the developer, it provides various features to developers to create their own features and add it inside Whatsapp itself.

Objective

  • To create bot support on the most used messenger platform out there.
  • To create a way for developers to make their own features inside whatsapp itself.
  • To teach developers how to use Supbot API using video tutorials.

Technology Stack

Supbot is made using

Bug Fixes

Bot taps the wrong chat if it shifts up or down due to new messages in other group

Cause?

  • the webview of chatgroup list item was cached which swapped when a listitem shifts up and down to different group during execution.

Fix?

  • find the webview everytime it is needed (removed cached webview for chatgroup listitem)

CheckerThread crashes when a group without Strings.groupTitlePrefix(";;") gets a message

Cause?

  • Group title name was split by Strings.groupTitlePrefix(";;") and the 2nd item in the array is checked as the groupid, if the group doesnt have groupTitlePrefix it would give IndexOutOfBoundExeption

Fix?

  • After splitting, check if the list have more than 2 elements, before using the 2nd item, to search for groupid

Bot crashes when a message with just an emojie is sent

Cause?

  • CheckerThread crashes when it tries to find text in the Bubble when there is none.

Fix?

  • Added exception handling when bubble doesn't contain any text.

Blob in ScheduleDatase gets currupted when UpdateSchedule was used

Cause?

  • object name was being saved instead of bytes of serialized object

Fix?

  • Store Serialized schedule object in the blob as bytes instead of its name.

XPaths Updates

Whatsapp Web keeps on updating from time to time, which breaks the bot, hence XPaths have to be updated when it changes.

Updated XPaths include:

  • inputText
  • newChatGroup
  • bubbleToAuthorName

New Features

Added way to tag people with phone number

Why?

  • Supbot reads the phone number of client to create unique id, which is then used to refer them too
  • As people usually don't recognize the person using their phone number, it wasn't a good design to refer them using their phone number
  • So, tagging could be used to refer the client in text

How?

  • To use this feature, SendMessageAction.tagPhoneNumbers() should be used when SendMessageAction is created to enable this feature, tagPhoneNumbers() takes a regex pattern string as a parameter so that it can be used to recognize if any phone number is there in the text.
  • when a phone number is found, it is converted into a tag, by placing @ symbol before the number and UP+ENTER keystrokes after the number, to convert it into a tag.
  • This feature is kept as an experimental feature as it hasn't been tested much.

Added way to send arguments with space using quotes in ConsoleCommands

Why?

  • There was a need to pass arguments with space like phone number in +xx xxxxx xxxxx format in the console.

How?

  • Regex patter matcher was used to find quotes, and the part inside the quotes was taken as a single parameter, and the parts outside the quotes were taken as multiple parameters separated with spaces.

Created ScheduleTaskInitializer

Why?

  • ScheduleTaskInitializer helps convert arguments (array of strings) into ScheduleTask object.
  • It is used by ScheduleCreateCC to create schedules using console commands, rather than inside code manually.

How?

  • First, class object of the class derived from the ScheduleTask class has to be added into the ScheduleTaskInitializer.scheduleTasks List.
  • Then when a ScheduleTask object is needed, ScheduleTaskInitalizer.getSceduleTask() method is called with the string arguments.
  • First argument is the name of the class, which is then used to get its constructor and the data types of the parameter in it.
  • Then each of the string from 2nd one is parsed into the respected data type.
  • Converting primitives like int, float, bool, etc.. is pretty straight forward, its just have to be parsed from string to their respective types, but parsing custom classes like ChatGroup requires it to have public static Object castFromString(String s); method in it which is then used to convert the string into its object.
  • then these objects are used to create the ScheduleTask which is then returned in an out object along with ScheduleTaskinitalizer.Response enum which contains the response (whether it was success or which error it encountered)

Created ScheduleCreateCC console command

Why?

  • ScheduleCreateCC initializes schedule using Console Command,
  • In previous version, it was needed to initialize a Schedule for the first time, after which it is stored in the database and loaded automatically when executed next time.
  • So the initialization code had to be manually written and executed once, then deleted as that part of code is no longer needed.
  • This made developing Schedule very tedious, hence a way was needed to initialize schedule using console commands

How?

  • ScheduleCreateCC extends ConsoleCommand which enables it to execute a block of code when a command is entered along with its arguments.
  • The string arguments are parsed into the datatypes needed to create a Schedule,
  • ScheduleTaskInitalizer is used to converted array of string arguments into ScheduleTask object which is needed to create a Schedule.

Created ScheduleDBDeleteCC console command

Why?

  • Once a Schedule is created, it is serialized and stored in the database in case the bot shut downs and is executed again,
  • But when the ScheduleTask class is changed, the serialized schedule object no longer can be loaded.
  • Hence a quick way was needed to delete the target schedule from the database

How?

  • ScheduleDBDeleteCC extends ConsoleCommand which enables it to execute a block of code when a command is entered along with its arguments.
  • The command takes 1 arugment which is the name of the schedule it is saved by, then it calls Bot.getScheduleManager().dbDelete(name) which calls ScheduleDatabase.DeleteSchedule(name)

Changes

Made Schedule.nextSchedule() method public

Why?

  • When a Schedule is missed, ScheduleTask.taskMissed() method is ran, which is defined by the developer using the API.
  • It is upon that developer to re schedule the task if it is missed, which become very tedious to do if they just want to re schedule it with respect to current time.

Changed name of RemoteActionCall to StringActionInitializer

Why?

  • RemoteActionCall class name didn't had the correct intuition of the content of the class, so StringActionInitializer name was better fitting for it.

Made ScheduleManager.notifyUpdate() public

Why?

  • It was required for the developers using the API to update the database once they changed some variable in schedule or schedule task.
  • Hence, making notifyUpdate() method public, made it possible to do so.

Roadmap

Development for Supbot API has finished (Since 3 months), but as developers using the API request new features or some bad design in the bot is noticed, I will try my best to add/change it in the bot.

How to contribute?

You can contribute this project by,

  • Using the the API and creating issue when any bug is encountered.
  • Helping me in the development by bug squashing or developing new features. (If you want to do this, contact me so that we can collaborate.)
  • Let me know if you have any good feature ideas.

Contact

If you have any problems or you want to contact me for feature ideas or want to collaborate in development you can contact me on DefineX Community discord server

GitHub Account

https://github.com/adsau59

Sort:  

Thank you for your contribution. As @reazuliqbal already mentioned it is better to create a pull request and write all the updates in that instead of writing in the commit messages.

Also just to be clear that according to our guidelines we only take into consideration new features or enhancements and not bug fixes i.e. "Bug Fixes for contributor’s Own Projects will not be considered for potential reward, unless the Bugs were caused by third party dependencies."

I really like the way you have written the description of the class files, good work.

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]

Thank you for your review, @codingdefined!

So far this week you've reviewed 8 contributions. Keep up the good work!

Hi @adam-saudagar, it seems an interesting project to me though I do not know Java.

If you make small meaningful commits it makes it easier for a moderator to check your work and give better scores. I saw that your commit has a description of what you have added or updated. Its better to use pull request and merge for better organization of commits.

Here is a guide by a @utopian-io moderator to score high at development contributions.

You have a minor misspelling in the following sentence:

Regex patter matcher was used to find quotes, and the part inside the quotes was taken as a single parameter, and the parts outside the quotes were taken as multiple parameters seperated with spaces.
It should be separated instead of seperated.

lol, good bot
here have a treat 🍖

Hi @adam-saudagar! We are @steem-ua, a new Steem dApp, computing UserAuthority for all accounts on Steem. We are currently in test modus upvoting quality Utopian-io contributions! Nice work!

Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 3 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 18 SBD worth and should receive 123 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

Hey @adam-saudagar
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

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

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.31
TRX 0.12
JST 0.033
BTC 64485.37
ETH 3156.53
USDT 1.00
SBD 4.05