Question about the package #11
-
Hi, I'm Gabriele, from Italy. I'm new to coding, because I just have used MATLAB and a bit of C++ during my studies. However for my thesis work, i have to realize a chatbot on WhatsApp that can understand (recognizing some words in the text message) what the user i saying and provide predefined answers. So it is a rule based chatbot, nothing to deal with AI. Since I'm new to coding I've struggled a lot in finding something easy to learn and do, but this python package seems perfect for what i have to do. I just didn't understand if there is the possibility to search words in the text message of the user so that I can provide my reply message (with if else and so on). Is there a function that does this operation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'm glad you found the package suitable for your use from pywa import WhatsApp
from pywa.types import Message
from pywa.filters import text
wa = WhatsApp(...)
@wa.on_message(text.matches('hi'))
def on_hi_message(client: WhatsApp, msg: Message):
...
@wa.on_message(text.matches('hello'))
def on_hello_callback(client: WhatsApp, msg: Message):
... Unless you want to be more dynamic, then you can do something more generic: @wa.on_message(text)
def on_message(client: WhatsApp, msg: Message):
match msg.text:
case 'hi':
...
case 'hello':
...
case 'bye':
... or with dict the triggers as the keys and the answers as the values We have a group on Telegram where they can probably go into more detail with you Good luck :) |
Beta Was this translation helpful? Give feedback.
Hi @GabrieleMassafra
I'm glad you found the package suitable for your use
If it is a number of predefined options (and which are not going to change), you can simply create some callbacks with filters for the text you want to handle:
Unless you want to be more dynamic, then you can do something more generic: