Chatbots are in fashion nowadays. Almost every business in an attempt to reduce costs or to allocate more work to human customer support tries to create a chatbot. Well, on my projects I don’t really a need a chatbot or any type of AI to provide support, so I tried to make a simple bot to use on my daily life. You know the type: to write ‘Hello, good morning’ to a group everyday, to reply back ‘thanks’ when it’s your birthday… Perfect for someone lazy!
Chatbots aren’t really that hard to create. There are loads of guides online, and amazing code is available on github for example. One of my favorites was a bot for whatsapp, an app I use daily. Oh and by the way, Facebook doesn’t like when you run bots on WhatsApp for a long time. They will ban you. So… avoid that.
Built with NodeJs it uses WAPI.js to provide a python interface for interacting with WhatsAPP Web to send and receive Whatsapp messages.
In bot.json you can edit the strings and the node application behavior:
{
"appconfig": {
"headless": false,
"isGroupReply":false,
"webhook":""
},
"bot": [{
"contains": [],
"exact": ["hi"],
"response": "{hello|howdy}"
},
{
"contains": [],
"exact": ["hello"],
"response": "hi",
"file":"noFile.png"
},
{
"contains": [],
"exact": ["hy"],
"response": "hi",
"file":"github.png"
},
{
"contains": [],
"exact": ["hiee"],
"response": "hi"
},
{
"contains": [],
"exact": ["github"],
"response": "Git Hub Logo",
"file":"github.png"
}
],
"blocked": [],
"noMatch":"{🤔|👍}",
"smartreply":{
"suggestions":[],
"clicktosend":true
}
}
As you can see by some strings, there’s not really any AI here. All the replies must be hand written, all the images must be self hosted. It’s simple, but fun.
There’s also some bots based on selenium that reply only on valid commands.
class BotConfig(object):
last_msg = False
last_msg_id = False
command_history = []
last_command = ""
def __init__(self, contact_list):
self.contacts = contact_list
def get_contacts(self):
return self.contacts
def set_last_chat_message(self, msg, time_id):
self.last_msg = msg
self.last_msg_id = time_id
def get_last_chat_message(self):
return self.last_msg, self.last_msg_id
def set_last_command(self, command):
self.last_command = command
self.command_history.append(command)
def get_command_history(self):
return "You have asked the following commands: " + ", ".join(self.command_history)
Also… keeping up with python, here’s another fun one. Like-My-GF: You setup the “target” name, setup a cron job and that’s it. Every time your SO posts something on instagram, your like is there!
CONFIG = dict( client_id = config_parser.get('Client', 'client_id'),
client_secret = config_parser.get('Client', 'client_secret'),
redirect_uri = config_parser.get('Client', 'redirect_uri'),
)
OTHER = dict( scope = ['likes'],
access_token = config_parser.get('Access Token', 'access_token'),
target = config_parser.get('Target', 'username'),
log_path = config_parser.get('Path', 'log_path')+'like_my_gf.log',
)