https://discord.gg/botpress logo
How to Limit Hooks to Certain Nodes and Override N...
# 🤝help
r
Hi everyone, I've been trying to use Hooks for Autonomous Nodes as a way to send the user messages and original LLM generated responses to an external API. The API will then return a new response that will be sent by the autonomous node to the user. However, I can't seem to find a way to limit the hook to only trigger in the nodes I want it to. I've tried using the
event.state.context.currentNode
variable but I can't seem to match it with my node name. The code I used is as follows:
Copy code
if (event.state.context.currentNode === 'node:<Node Name>') {
  // Code to execute
}
Is there a way to limit the hook to only trigger in certain nodes? Furthermore, I've also tried to override the response sent by the node with the new response returned by the API. However, I can't seem to find the variable I need to override to implement this. I've tried overriding the
execution
and
event.payload
variables. Is there a way to override an autonomous node's response inside a hook? Thank you in advance!
l
Hey, the currentNode usually gives you the node ID, not the display name. Log event.state.context to see the exact value and match against that. For overriding the response, don’t touch event.payload — instead update the output object (e.g. event.output.text = apiResponse.newText). If available, a beforeReply hook is the cleanest place to do it. If you find it difficult to fix, you can reach out to me bro
r
Hi Isaac, Thanks for your suggestions. I tried a couple more times and I think I found the working solution for both problems. For the
currentNode
check, I initially got confused because the value shown in the log was always in the
node:<Node Name>
format. Instead like you said, we need to match it against the node's id (something like
nd-<Node ID>
). For the output override, I got it working by overriding both
outgoingEvent.payload
and
outgoingEvent.preview
with the API's return value. Thanks again for your help