Thulani Introduction: Slack Bot For Investment Management

Written by Stephen Chapendama | Published 2020/08/08
Tech Story Tags: chatbots | investing | ibm-watson | future-of-ai | finance | slack | programming | software-development

TLDR This is the story of Thulani, a chatbot I designed to make my life easier and also help me understand ChatOps more. ChatOps is the use of chat clients, chatbots and real-time communication tools to facilitate how software development and operation tasks are communicated and executed. This post is a guide to what tools and resources I used to understand chat ops more, and how you can use chatbots to solve (hopefully better) problems. For example, the ‘Hello’ node was my initial conversation starter. When a user opens the chatbot, how will the user greet them? Of course, he can just greet them and wave whilst waiting for input.via the TL;DR App

This is the story of Thulani, a chatbot I designed to make my life easier and also help me understand ChatOps more. I wish there was more to it than that, I really do, but this post is a guide to what tools and resources I used to understand chat ops more, and how you can use chatbots to solve (hopefully better) problems.

What is chat ops?

ChatOps is the use of chat clients, chatbots and real-time communication tools to facilitate how software development and operation tasks are communicated and executed.

Why did I need a chatbot?

I’ve recently started using the platform Freetrade by the Freetrade Team. I am not a serious investor, it first started off as interest and wanting to own shares in some of my favourite companies, but over time as more friends signed up, we started having discussions and researching stocks.
But during this research, I have found it difficult to keep up with every stock, especially the ones I just want to keep an eye out on. What this meant was that sometimes I could miss out on a buy or a potential exit. So I sat down and had a think, how can I build something for myself to ensure this doesn't happen?
Disclaimer: Other apps have features that could eliminate this problem, but that doesn’t teach me about chatbots now does it 🙃
And Project Thulani was born!
The first step was to name my chatbot and to officially start this project. I chose the name Thulani which is of Zulu origin. It means to “be quiet/be comforted.” I liked the name and felt it would give my chatbot more character, and how often do we see bots with Zulu names?
Having identified my problem and the proposed solution, it was now time to envision what success will look like:
A user finds a share → User informs Thulani → Thulani checks API with stock information → User confirms → End. 
This was the draft user story I was trying to build, where each time I decide to monitor a companies stock, Thulani will remember the time and date as this will be the price point I will want to monitor, and then I can set Thulani to message me if the price goes below or above X.
As I didn’t actually want to create an entire app for just this function, a chatbot was the best solution.

Thulani meets Watson!

Watson Assistant is IBM’s AI product that lets you build, train, and deploy conversational interactions into any application, device or channel. I chose to explore Watson as the backend to Thulani’s conversation skills as unlike most chatbots, Watson Assistant doesn’t try to mimic human interaction.
It will actually ask for clarity, know when to search from a knowledge database (the API we will be querying) and can be deployed on Slack amongst other things.
I was able to deploy an instance of a Watson Assistance which I could actually preload with some customer service conversation skills, but there was nothing that really covered the questions I was looking for, so I had to teach Thulani how to respond, from scratch.
The ‘Hello’ node was my initial conversation starter. When a user opens the chatbot, how will Thulani greet them? Of course, he can just greet them and wave 👋🏾 whilst waiting for input, but it makes more sense to get the most out of the interactions (as this means you write fewer conversation nodes).
So Thulani would greet the user, and immediately ask what stock they are after. But this is a bad way to write up dialogue. As it boxes my chatbot into limited functionality. If there’s scope for it to grow, I would like the first interaction to actually be like a menu, so Thulani will let the user straight away, “Hey, here are your options!”

Then came the headache 🤯

With the logic written out, I now came to the realization that I would now need to integrate an API for the stock information. But with only 10,000 API calls a month, the infrastructure engineer within me kicked in. How can I gracefully preserve the API calls? Thulani should be able to check Tesla's share price without my interaction and then feedback to me if Elon has crashed the market.
But what happens at weekends or when the stock markets are closed? It meant that I had to find a way to add logic and operating hours for Thulani.
Function only during weekdays between 8 am and 9 pm. (This is when the UK and USA stock markets are open)Do not make API calls on weekends — Unless asked by the user.
But even with these questions to answer where was I getting the data from?
The data needs to be liveish. If it’s not liveish, Thulani needs to let me know the last time it was checked.
Thulani needs to keep a log of the last time I asked and update me if the stock is up or down since then. The API 🕸
Thanks to Shen Huang who published The Best 5 free stock market APIs in 2020 I was able to find an API that would satisfy what I need. I chose to use yfinance as the historical data it holds could actually be useful in the future, wouldn’t it be great to ask Thulani how oil was doing during the recession of 2008?
But it wasn’t compatible with Watson as there is currently no webhook available. And as I was trying to make this a free resource, investing in running a VM that would communicate with Watson was not feasible. I did look for webhook versions to pull this information but they all come with a cost.

End of the road for Thulani? 🥺

One thing I often preach about is to practise makes perfect and trying new things is the best part of keeping up with computer science & tech. I am in no way a Software Engineer or even someone who works with chatbots, but this weekend I was able to try out a new side of tech, using low code solutions to try and build a chatbot.
My friend Stephen Wond who is a Software Engineer focusing on AI also took on this challenge and took a completely different approach, going the Microsoft route and using Microsoft LUIS. For both of us, it was a chance to rethink problems in our fields that could be solved with chatbots. In regards to cybersecurity and data science, there are actually so many different use cases I can now look forward to trying out with a chatbot.
For example, I currently run multiple honeypots and it would be great to set up a Telegram bot where users can ask if an IP has appeared in my honeypot data, or daily stats and figures about the attack landscape.
Watson may not have been the best choice for my project, but this doesn’t mean it’s the end of Thulani, as Stephen Wond has had far better success with LUIS, I will be looking to brush up on my Azure skills (and hopefully secure some Azure credits 🤣, Hi Microsoft UK Developer).
This was a fun way to learn by doing, but although this time, I didn’t come through with the prototype I would’ve wanted, I am looking forward to getting back to learning and rebuilding Thulani 2.0 🤖
If you are looking to get involved in the development of Thulani, please connect with me on LinkedIn: Stephen Chapendama

Written by Stephen Chapendama | Cyber Security Professional & Technology Manager @ Foundervine
Published by HackerNoon on 2020/08/08