https://discord.gg/botpress logo
disable bot under certain conditions
# 🤝help
b
Hello team, Is there a way to disable the bot, that is prevent it from answering any questions if a variable is set to true? also is there a way to have a time of life on that variable? i.e. when the variable is set to true, it remains true for 24 hours and then reverts back to false?
g
yes, the method depends on your architecture but its possible regardless of your architecture. the time line question you can achieve in various ways. One method would be to save the variable when its set in a table, query it when you use it, and only if its been 24 hours since created, then change its value back to false. but like i said it massively depends on architecture.
b
Hey @gentle-policeman-89141 thx for the response. In such a case, is there a way to do that via hook? i.e. before passing through the bot, check the table, if value is present and not yet expired to skip the bot completely? i believe there are ways in the doc detailing how to search a table via code, but i didnot find a way to skip the bot flow completely. Any ideas here how to proceed?
l
For your first question if youre using an autonomous node, you can explain exactly that in the instructions and it should work as intended!
Will get back to you on the timed variables @breezy-belgium-57865
b
@loud-crowd-60573 my logic is a mix of both autonomous and traditional cards, is there a way to do this via hooks? i.e.
Before Incoming
if logic is true, skip to
After turn End
directly without passing through the bot?
g
Do you want your bot to not respond at all or to respond something static and unchanged?
you may be able to do something like; before outgoing hook, check the table, if the flag is true, intercept the outgoing message before its sent and re write it
i did something similar here:
Copy code
const devTag    = '[DEV]';
  const devUserId = 'user_01JRMSSSGHQ3Z2ZF5CTMCJ14AK';  // My user id: user_01JRMSSSGHQ3Z2ZF5CTMCJ14AM

  const text   = outgoingEvent.payload?.text;
  const target = event.userId;

  console.log('[HOOK] outgoingEvent.target=', target, ' text=', text);

  // If it's a dev-only message *and* we're NOT talking to the dev user...
  if (typeof text === 'string' &&
      text.startsWith(devTag) &&
      target !== devUserId) {
    // …then overwrite it with something benign (even an empty string works):
    outgoingEvent.payload.text = '';  
    console.log('[HOOK] stripped DEV message for', target);
  }
this was a before outgoing hook, that checks to see if the outgoing message is tagged at the start with '[DEV]', if so, intercepts outgoingEvent.payload.text and makes it not send the message basically (empty string)
may not be perfect for your use case though
b
Hey @gentle-policeman-89141 thats great, in my case though i want the bot not to respond at all...
g
Set the flag, if that flag is true, just route to empty node or end node
probs the easiest way
b
do you know how to route to an empty node via code?
g
can i see a screenshot of your workflow
b
in hook
Before Incoming
check condition, if true then route to that empty node
g
jumping to other nodes from code block i havent done, i believe the bp object has a jump to function, but ive never used it. the most reliable way is to set a variable to true (user. , bot. etc the scope depends on your needs, if you just dont want the bot to respond to a certain user, use user scope, if you dont want bot responding to all users, use bot scope) then in your workflow, use an expression card, set the expression to (for example) user.noReply or explicitly: user.noReply === true. and connect the expression to an empty node.