Possible bug when using actions
-
I’m new to using AI Engine so it’s likely what I’m doing is wrong but what I’m doing is generating errors in the client when trying to use an action. The reason for finding out about actions is to be able to call JavaScript functions when the chat bot being prepared. There is probably a better way using the cloient API but, as a newbie I’m looking at all options.
My action is defined by using ‘mwai_chatbot_actions’ filter and returning this block:$actions[] = ['type' => 'function', 'data' => 'name' => 'myFunction', 'args' => [] ] ];
The function is called. It is called by evaluation in the client (see the screenshot) which works OK. The evaluation is performed in a function that expects two parameters: ‘actions’ and ‘lastMessage’. When the function is called by it’s parent, the actions argument is passed but lastMessage is undefined.
You will see in the screenshot, highlighted in yellow, lastMessage is used and the expectation is the variable will be an object. As it is undefined, JavaScript throws an exception not processing any further information.
It would work if the line started
!lastMessage?.content
but as it is, JavaScript tries to read the property ‘content’ of an undefined variable. Maybe i don’t need to use an action, maybe I’m doing something wrong. But in the event it is a bug, I hope this message helps.
Best wishes.
- You must be logged in to reply to this topic.