Trying to make a whatsapp bot
I am trying to make a WhatsApp bot inspired by the functioning of Discord bots, the bot will work in WhatsApp groups.
I have looked up the official WhatsApp Business API but I am not sure that they will not approve my number as it is just a hobby project and not a proper "business".
There is an alternative though and that is the Twilio WhatsApp API. However, they provide you with a sandbox. I can interact with it in DMs but as the sandbox number is a business account, I cannot add it to a group like discord.
I intend to write a server in python or node.
Can anyone share a solution or workaround? Only if I could add the Twilio number to a group my problem will be solved. Though I am ready to use any other API/Solutions for this.
There is actually a Python solution for this. It is a pain to set it up, but it still works. Check it out:
https://github.com/mukulhase/WebWhatsapp-Wrapper
It uses the webdriver Selenium to send/retrieve messages through Web-WhatsApp.
Be aware that it is against their rules, so your phone number might get banned!
Thanks! Actually I already implemented stuff with this on twitter using selenium and geckodriver (web driver for firefox). It works like a charm. However, this is not what I was looking for. I did not mention in the question, however, I wanted to host the bot on a server. The Whatsapp client sends a GET request to my server and then my server responds back with a message (A WhatsApp request object) . At least this is how its done on Twilio. However, Selenium/Geckodriver may not be the best option for a server of which I have only CLI access. I don't even know if the server can run web browser.
You are right, i'm not sure if it will work on a server without GUI. I'll give it a shot this week, will let you know if I can make it work!
Sure good luck! In the meantime, I searched a lot, apart from your solution, I found no other solution. So I have pretty much given up on this for now. Looks like I will make a discord bot instead. If you give it a try though, I think you might find phantomJS useful. It uses selenium, but this browser is hidden instead of normal browsers like firefox or chrome. This may (I am not sure) work on CLI. Please let me know of the results.
I managed to get it work on a Linux server (without GUI) using docker! Just follow their Docker and remote Selenium Installation instructions
You can use this replit template by forking it.
https://replit.com/@AllailQadrillah/Whatsapp-Bot
WhatsApp bot is built using the unofficial api from whatsapp-web.js which can save sessions on mongodb and is active for 24 hours
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
When linking to your own site or content (or content that you are affiliated with), you must disclose your affiliation in the answer in order for it not to be considered spam. Having the same text in your username as the URL or mentioning it in your profile is not considered sufficient disclosure under Stack Exchange policy.