Intent routing #94
Replies: 3 comments 3 replies
-
Interesting idea (and thanks for introducing semantic-router ;)) The thing is this: Since the library is designed so that several handlers will handle the same update, it was important to me to make sure that the content of the update cannot be changed (so that we don't have to give a new copy each handler) Something like this: @app.on_message(filters=filters.text, priority=100) # a higher priority will be executed first
def on_every_text_message(_: WhatsApp, m: types.Message):
m.data["key"] = "value" # .data is a dict that can be used to store data between handlers
m.continue_handling() # continue to the next handler
@app.on_message(filter.new(lambda _, msg: msg.data["key"] == "PURCHASE"))
def handle_to_purchase_intent(_: WhatsApp, msg: types.Message):
msg.reply("Here is our catalogue of products...")
@app.on_message(filter.new(lambda _, msg: msg.data["key"] == "Negative"))
def handle_negative_experience(_: WhatsApp, msg: types.Message):
msg.reply("I am sorry your experience has not lived up to your expectations") Do you think this could be useful? |
Beta Was this translation helpful? Give feedback.
-
I think this would be one of the easiest things to implement. just to add the field to |
Beta Was this translation helpful? Give feedback.
-
Ok, but i think i'll stick with pip install https://github.com/david-lev/pywa/archive/update-shared-data.zip I'll try yo publish new version in the next days |
Beta Was this translation helpful? Give feedback.
-
I am trying to build in intent routing to my Whatsapp bot using semantic-router (https://github.com/aurelio-labs/semantic-router).
Currently, my understanding is that you can do this by having a handler that is triggered on all incoming messages and then build your custom logic there, ie:
However, this could quickly become a bit unmaintainable for more complex logic, and I really love the pyWa filtering on the handlers as it makes the code so concise and easy to read and understand. One thing that would be really neat is if it was possible to build some kind of middleware that adds arbitrary information to the msg object and can later be used to filter on. A python interface could look something like this:
Beta Was this translation helpful? Give feedback.
All reactions