Make Quriobot sensitive to Time of day and have different responses or jumps based on the time of day

To make Quriobot sensitive to the time of day and subsequently program your bot to have different responses or jumps based on the time of day just follow these steps:

Note: you can see a demo bot here

We will make use of the script variables.

Step 0: Enable developer mode

Step 1: Create a script variable named greeting:

function(callback, variables) {
  var hourNow = quriobot.moment().hour()
  if (typeof variables.userTimezone.value !== "undefined") {
      hourNow = quriobot.moment().utc().utcOffset(parseFloat(variables.userTimezone.value)).hour();
  var greeting;
  if (hourNow >= 18) {
    greeting = 'Good evening!';
  } else if (hourNow >= 12) {
    greeting = 'Good afternoon!';
  } else if (hourNow >= 6) {
    greeting = 'Good morning!';
  } else if (hourNow >= 0) {
    greeting = 'Good night!';
  } else {
    greeting = 'Welcome!';

In the above code the function " today.getHours()" is used, which gives the hour of the day (24 hour). After that I made a split of three parts of the day in order to be able to respond and jump based on that, but also use it as a message. If you want to use different timeframes or settings please visit this page for more options and information

Step 2: You can now use the above-created solution by using {{greeting}} in your bot. So if you want to use the as a chat message, bot response message, response connections, just use it like this:

Step 3: So how about making the bot start on different Steps based on this function?If you want that you will need to capture the {%api.greeting%} in a GoTo Step otherwise you cannot use the advanced conditions used for those different Steps.

  • Add aGoTo Step to the top of your list and add {{greeting}} as a value there:

    Note: After passing Step 1 in the bot it will contain the value of the strings from the script variable created above.

  • You could already use the responses of this GoTo step to make different jumps but in this example, I first jumped to Step 2 where in theResponses, I created the advanced conditions for different jumps

    • Add aresponse (and depending on the Step type, choose an Answer option (in this case “Yes”)
    • Switch on theAdvanced Conditions
    • Set up therules. In this case, I configured that based on the strings I set in the Advanced Initialization(see above) so I can now, for example, say Step 1 contains “morning”
    • Configure the jump (in this case it Jumps to Step 3 it contains “morning, Step 4 if it contains “Afternoon” and Step 5 if it contains “Evening”)

That’s it! A bot that jumps to (and thus can also start on) different Steps in your bot based on the time of day!

Edit this page

See also