rivescript-python icon indicating copy to clipboard operation
rivescript-python copied to clipboard

Adding and getting dynamic triggers

Open lynxionxs opened this issue 9 years ago • 3 comments

Is it possible to getand add triggers dynamically ? For example from a redis store. To be able to add triggers without restarting the bot.

routes = {
    "topic=domath": {
        "math": {
            "triggers": getTriggersFromRedis,
            "args": "<star1> <star2>",
            "handler": doMath
        },
        "wildcard": {
            "triggers": ["*"],
            "args": "<star>",
            "handler": wildcardHandler
        }
    }
}

This way i can also let the bot add new triggers by itself, based on the wildcard message for a topic. It will search for certain keywords like action verbs, question verbs etc... in the wildcard message, then determine where to create the new trigger.

lynxionxs avatar Aug 31 '16 09:08 lynxionxs

You can use stream() to add new triggers whenever you want (make sure to call sortReplies() afterward so they're actually matchable).

The router example code exists entirely outside the rivescript library so you can make it do whatever you need for it to get stuff from Redis or whatever.

kirsle avatar Aug 31 '16 17:08 kirsle

Oh, i did'nt know stream() could be used to "livestream" triggers without restarting the bot. Not sure if sortReplies() would require a restart though. That will not be ideal in this situation. I want the bot and rivescript code to be as dynamic as possible. Meaning less hardcoded triggers.responses in the files. Thanks though.

lynxionxs avatar Aug 31 '16 20:08 lynxionxs

sortReplies() can be called multiple times without a restart. It deletes the sort buffers and remakes them from scratch each time.

kirsle avatar Aug 31 '16 21:08 kirsle