Supbot API | Whatsapp Group Chatbot API | Developement update #2 by adam-saudagar

View this thread on steempeak.com
· @adam-saudagar · (edited)
$35.49
Supbot API | Whatsapp Group Chatbot API | Developement update #2
<center>
![supbot banner](https://cdn.steemitimages.com/DQmVfVL98g7QbEyb4t4bt5A9DuMZLBYpiekwceBswjSUqTJ/small%20banner.jpg)
</center>

It has been 3 months since the last development update, as I was pretty busy with other projects and making [video tutorials](https://www.youtube.com/playlist?list=PLdeajH45r2EKfD4lB6LJW6jF66PLSFGFa) for this one and  also I was looking for a big update change [(Commit3)](https://github.com/adsau59/supbot/commit/5115e25e31dbf1613f25ac724a57bba7bf2d65b6) 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](https://github.com/adsau59/supbot/commit/bc05040dd21ed9fa04cfd0d3fcbccbbefb020538)
[Commit2](https://github.com/adsau59/supbot/commit/ad504e9416ef61979ef1f743fc9271c05280f328)
[Commit3](https://github.com/adsau59/supbot/commit/5115e25e31dbf1613f25ac724a57bba7bf2d65b6)

### What is Supbot API?
Supbot API is a Whatsapp Group Chatbot API, [Showcase video](https://www.youtube.com/watch?v=MWCjVzM0rW8).

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](https://www.youtube.com/playlist?list=PLdeajH45r2EKfD4lB6LJW6jF66PLSFGFa).

### Technology Stack
Supbot is made using
- [Java Development Kit 8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
- [Selenium](https://www.seleniumhq.org/)
- [JDBC](http://www.oracle.com/technetwork/java/javase/jdbc/index.html),  [google-gson](https://github.com/google/gson), [Apache HttpComponents](https://hc.apache.org/)

### 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](https://discord.gg/V6e2fpc)

### GitHub Account
https://github.com/adsau59
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
post_id60,065,199
authoradam-saudagar
permlinksupbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2
categoryutopian-io
json_metadata{"tags":["utopian-io","development","whatsapp","java","selenium"],"image":["https:\/\/cdn.steemitimages.com\/DQmVfVL98g7QbEyb4t4bt5A9DuMZLBYpiekwceBswjSUqTJ\/small%20banner.jpg"],"app":"steemit\/0.1","format":"markdown","links":["https:\/\/www.youtube.com\/playlist?list=PLdeajH45r2EKfD4lB6LJW6jF66PLSFGFa","https:\/\/github.com\/adsau59\/supbot\/commit\/5115e25e31dbf1613f25ac724a57bba7bf2d65b6","https:\/\/github.com\/adsau59\/supbot","https:\/\/github.com\/adsau59\/supbot\/commit\/bc05040dd21ed9fa04cfd0d3fcbccbbefb020538","https:\/\/github.com\/adsau59\/supbot\/commit\/ad504e9416ef61979ef1f743fc9271c05280f328","https:\/\/www.youtube.com\/watch?v=MWCjVzM0rW8","http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jdk8-downloads-2133151.html","https:\/\/www.seleniumhq.org\/","http:\/\/www.oracle.com\/technetwork\/java\/javase\/jdbc\/index.html","https:\/\/github.com\/google\/gson","https:\/\/hc.apache.org\/","https:\/\/discord.gg\/V6e2fpc","https:\/\/github.com\/adsau59"]}
created2018-08-18 13:38:42
last_update2018-08-19 09:04:15
depth0
children8
net_rshares26,764,690,446,680
last_payout2018-08-25 13:38:42
cashout_time1969-12-31 23:59:59
total_payout_value26.757 SBD
curator_payout_value8.735 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9,550
author_reputation4,774,071,168,640
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (32)
@grammarnazi ·
Minor Correction
You have a minor misspelling in the following sentence: <blockquote> 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.</blockquote> It should be <i>separated</i> instead of <i>seperated</i>.
πŸ‘  ,
properties (23)
post_id60,065,206
authorgrammarnazi
permlinkre-adam-saudagar-supbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2-20180818t133829763z
categoryutopian-io
json_metadata{"app":"steemit"}
created2018-08-18 13:38:48
last_update2018-08-18 13:38:48
depth1
children1
net_rshares7,314,602,286
last_payout2018-08-25 13:38:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length340
author_reputation-144,174,644,390
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@adam-saudagar ·
lol, good bot
here have a treat πŸ–
πŸ‘  
properties (23)
post_id60,065,607
authoradam-saudagar
permlinkre-grammarnazi-re-adam-saudagar-supbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2-20180818t134359550z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit\/0.1"}
created2018-08-18 13:44:00
last_update2018-08-18 13:44:00
depth2
children0
net_rshares4,557,689,705
last_payout2018-08-25 13:44:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length33
author_reputation4,774,071,168,640
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@reazuliqbal ·
$0.03
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](https://steemit.com/utopian-io/@gregory.latinier/how-to-achieve-the-highest-score-for-a-better-utopian-reward-for-the-development-contributions) by a @utopian-io moderator to score high at development contributions.
πŸ‘  , ,
properties (23)
post_id60,071,634
authorreazuliqbal
permlinkre-adam-saudagar-supbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2-20180818t150340227z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https:\/\/steemit.com\/utopian-io\/@gregory.latinier\/how-to-achieve-the-highest-score-for-a-better-utopian-reward-for-the-development-contributions"],"users":["adam-saudagar","utopian-io"],"app":"steemit\/0.1"}
created2018-08-18 15:03:42
last_update2018-08-18 15:03:42
depth1
children0
net_rshares25,869,020,428
last_payout2018-08-25 15:03:42
cashout_time1969-12-31 23:59:59
total_payout_value0.028 SBD
curator_payout_value0.006 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length587
author_reputation53,978,675,295,884
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (3)
@codingdefined ·
$10.21
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](https://join.utopian.io/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](https://review.utopian.io/result/3/2332211).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , ,
properties (23)
post_id60,141,602
authorcodingdefined
permlinkre-adam-saudagar-supbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2-20180819t111846678z
categoryutopian-io
json_metadata{"links":["https:\/\/join.utopian.io\/guidelines","https:\/\/review.utopian.io\/result\/3\/2332211","https:\/\/support.utopian.io\/","https:\/\/discord.gg\/uTyJkNm","https:\/\/join.utopian.io\/"],"app":"steemit\/0.1","tags":["utopian-io"],"users":["reazuliqbal"]}
created2018-08-19 11:19:33
last_update2018-08-19 11:19:33
depth1
children1
net_rshares7,628,059,567,626
last_payout2018-08-26 11:19:33
cashout_time1969-12-31 23:59:59
total_payout_value7.688 SBD
curator_payout_value2.519 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,045
author_reputation71,157,752,447,147
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (9)
@utopian-io ·
$0.02
Thank you for your review, @codingdefined!

So far this week you've reviewed 8 contributions. Keep up the good work!
πŸ‘  ,
properties (23)
post_id60,336,900
authorutopian-io
permlinkre-re-adam-saudagar-supbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2-20180819t111846678z-20180821t122509z
categoryutopian-io
json_metadata{"app":"beem\/0.19.42"}
created2018-08-21 12:25:12
last_update2018-08-21 12:25:12
depth2
children0
net_rshares16,419,921,927
last_payout2018-08-28 12:25:12
cashout_time1969-12-31 23:59:59
total_payout_value0.018 SBD
curator_payout_value0.004 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length116
author_reputation152,913,012,544,965
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@steem-ua ·
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!
πŸ‘  
properties (23)
post_id60,142,225
authorsteem-ua
permlinkre-supbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2-20180819t112930z
categoryutopian-io
json_metadata{"app":"beem\/0.19.54"}
created2018-08-19 11:29:30
last_update2018-08-19 11:29:30
depth1
children0
net_rshares4,675,080,196
last_payout2018-08-26 11:29:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length190
author_reputation23,203,609,903,979
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@trufflepig ·
**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.](https://steemit.com/@trufflepig/daily-truffle-picks-2018-08-19) 
    
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!](https://steemit.com/steemit/@trufflepig/weekly-truffle-updates-2018-33)
    
Have a nice day and sincerely yours,
![trufflepig](https://raw.githubusercontent.com/SmokinCaterpillar/TrufflePig/master/img/trufflepig17_small.png)
*`TrufflePig`*
    
πŸ‘  
properties (23)
post_id60,166,122
authortrufflepig
permlinkre-supbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2-20180819t164903
categoryutopian-io
json_metadata{}
created2018-08-19 16:49:03
last_update2018-08-19 16:49:03
depth1
children0
net_rshares4,675,080,196
last_payout2018-08-26 16:49:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length884
author_reputation37,535,693,521,838
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@utopian-io ·
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.**

<a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
post_id60,263,564
authorutopian-io
permlinkre-supbot-api-or-whatsapp-group-chatbot-api-or-developement-update-2-20180820t171032z
categoryutopian-io
json_metadata{"app":"beem\/0.19.42"}
created2018-08-20 17:10:33
last_update2018-08-20 17:10:33
depth1
children0
net_rshares0
last_payout2018-08-27 17:10:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length306
author_reputation152,913,012,544,965
root_title"Supbot API | Whatsapp Group Chatbot API | Developement update #2"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000