Title: Possible bug when using actions
Last modified: April 15, 2025

---

# Possible bug when using actions

 *  [bseddon](https://wordpress.org/support/users/bseddon/)
 * (@bseddon)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/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.
 * ![](https://wordpress.org/68589e5c-70d5-4937-9756-dbe380c54c4f)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [bseddon](https://wordpress.org/support/users/bseddon/)
 * (@bseddon)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/possible-bug-when-using-actions/#post-18417832)
 * ![](https://i0.wp.com/fws-dev-env-13.com/fwsbi/wp-content/themes/automation/misc_pages/
   ai-engine-actions-issue.jpg?ssl=1)
 * Here’s the screenshot
 *  Thread Starter [bseddon](https://wordpress.org/support/users/bseddon/)
 * (@bseddon)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/possible-bug-when-using-actions/#post-18417837)
 * I seem to have difficulty adding the screenshot. Here a link:
   [https://fws-dev-env-13.com/fwsbi/wp-content/themes/automation/misc_pages/ai-engine-actions-issue.jpg](https://fws-dev-env-13.com/fwsbi/wp-content/themes/automation/misc_pages/ai-engine-actions-issue.jpg)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Possible bug when using actions’ is closed to new replies.

 * ![](https://ps.w.org/ai-engine/assets/icon-256x256.png?rev=3431928)
 * [AI Engine - The Chatbot, AI Framework & MCP for WordPress](https://wordpress.org/plugins/ai-engine/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ai-engine/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ai-engine/)
 * [Active Topics](https://wordpress.org/support/plugin/ai-engine/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ai-engine/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ai-engine/reviews/)

 * 2 replies
 * 1 participant
 * Last reply from: [bseddon](https://wordpress.org/support/users/bseddon/)
 * Last activity: [1 year, 1 month ago](https://wordpress.org/support/topic/possible-bug-when-using-actions/#post-18417837)
 * Status: not a support question