Search code examples
python-3.xaimlrivescript

How to execute a Python3 object macro within Rivescript ".rive" script?


I have the following code within the .rive file for RiveScript Interpreter, the code basically will say hello world when the user type the command "give me result":

> object base64 python
    import base64 as b64
    return b64.b64encode(" ".join(args))
< object
+ encode * in base64
- OK: <call>base64 <star></call>

Now when running that with the interpreter with the command python3 rivescript eg/brain, I get the right expected results. But when I try to run it with the following code:

from rivescript import RiveScript

bot = RiveScript()
bot.load_directory("./eg/brain")
bot.sort_replies()

while True:
    msg = raw_input('You> ')
    if msg == '/quit':
        quit()

    reply = bot.reply("localuser", msg)
    print 'Bot>', reply

As it mentions here that Python support by default is on.

Edit: I forgott to mention the error I'm getting which is the following:

[ERR: Object Not Found]

Why I am getting this error?


Solution

  • Simple: Just reply to the bot with the trigger to that object macro.

    For example: To call the object macro described include the following trigger and reply in your .rive file:

    > object hello_world python
       print("give me result")
    < object 
    
    + hello world
    - <call>hello_world</call>