In the late of September 2024, I stumbled upon a TikTok video about an Indonesian developer creating a WhatsApp bot for his girlfriend. The bot itself is used when the said developer is away for work and can't reply to his girlfriend. (Shame on me because I'm maidenless.)
I think that the TikTok creator who made the bot is also selling the bot as a service. I also believe that the creator was skilled enough to create such a bot.
Then I, as a developer, wanted to challenge myself to create the same similar bot. Although much simpler by connecting the WhatsApp Chat API with OPENAI.
THE UNCHARTED WATERS
The first problem that I encounter during this project is the Concept of Chat Messages. I also think that the WhatsApp API is paid for use, even in the developer mode. But I'll breakdown my problems:
- The Concept of Chat Messages API (Message, Callbacks, and Events)
- ChatGPT vs. Ollama
- Is the WhatsApp API really paid for use?
These are the three main issues that I encounter. Number 1 is regarding the technicality. Points 2 and 3 are basically about my monetary resources that I don't have available at the moment. (Yes, I'm broke and unemployed. LOL)
DEFINING PROBLEMS
Concept of Chat Messages
So, I happen to create notification messages from webhooks. I know how to use them. But it wasn't in Whatsapp; rather, it was in Slack. Getting familiar with how the Slack works, partially. I tried to understand how it works first before I go to the main dish. (The WhatsApp API)
There's three things that I needed to know.
Callbacks
The callbacks are not so difficult; I know how it worked in the past. I did work with the FLIP Callback API for payment gateways about 2 years prior. Jog a little bit of my memories when trying to integrate into the Slack.Events
So, after I establish the callback, there's another thing called events. I don't really know how events are working, and it turns out that I needed to subscribe to events in order to send the related events that trigerred in the Slack APP to my callback API.Message
The callbacks have been set, and the events are configured to be sent into my backend. It's now time for the BOT to reply to the message. A simple if-else statement for the sake of the test is delivered.
ChatGPT vs Ollama
I think that chatGPT is paid for use, so I tried Ollama for this little project of mine. I learned how to use it, and to my surprise, it was so easy to use. I pull the DeepSeek Coder model and use the Ollama API service to create a prompt and get the generated response.
SLACK BOT + DEEPSEEK
My prototype of the bot is ready, but it wasn't in WhatsApp. It was still in Slack. 2 weeks just to wrangle the concept of messaging services was so worth it. It was a very exciting week that I had.
WHATSAPP BOT
Remember the 3rd problem about the WhatsApp being paid to use? turns out that the developer and testing environment is NOT paid to use. But after looking through the WhatsApp documentation and Indian Tech Videos (yes, we all did look at the Indian IT Tutorials), it wasn't really much of a different from Slack.
The steps are pretty simple. Aside from creating the META Developer and business account, with the whole team roles, and other mambo-jambo. It was fairly easy.
- Create a Meta Business App
- Create a bot and assign it to the Meta Business App.
- Create a system user within the business app that is authorized in the bot.
- Create an API key for the system user.
Yes, all steps above were a bit confusing and took me 4 days with the additional procrastination that I did. 😏😏
And then the same step as the Slack API:
- Set the Callback API
- Set the Events
- Test the Bot Reply
Its just the matter of connecting the Ollama with the Whatsapp API. Then VOILA!
This is far from good; it's just a simple project for me to not get bored. But hell yeah, bruv. This is very exciting. I think I'll make some little project and document it on the monthly or weekly devlogs until I get a job. Cheers guys! 😆😆