AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

topic Timeout
 
 

Using the Rivescript for Go programming… Works very well and have integrated it into a very nice chatbot application that helps our users troubleshoot events.  When a user is in troubleshooting mode, each step is a topic. The problem is they may go away, and then come back hours later and try to ask the chatbot another question—but they’re stuck inside the topic they left on which may be a few days ago. Is there a way to time out a topic? So that ten minutes later it goes back to topic=random?

I am also using the redis backend—so even if I restart the chatbot, it remembers where the user left off.

 

 
  [ # 1 ]

RiveScript itself doesn’t support this but you can implement it on your own in your app code.

Bad JavaScript example to give you a gist:

// you have a dictionary object of timeout objects per user
var timeouts = new Object();

// your custom reply function in your app
async function sendMessage(username,msg{
    let timeout 
timeouts[username];
    if (
timeout !== undefined{
        clearTimeout
(timeout); // cancel the timer on every new message
    
}

    let reply 
await rs.reply(usernamemsgthis);

    
// set a timer to reset the user topic after some while
    
timeout setTimeout(async function() {
        await rs
.setUservar(username"topic""random");
    
}1000 60 60 4); // 4 hour delay, in milliseconds
    
timeouts[username] timeout;  // so we can cancel it later

    
return reply;
}

(it’s a “bad example” because if this was running on a web browser, the user probably wouldn’t keep it open for 4 hours, so this would be server-side Node.js code, which doesn’t have setTimeout as that’s a browser API… but you get the gist).

The non-JS implementations of RiveScript work about the same way, except all their methods are synchronous, so you don’t have the `await` keyword (which is how modern async JS can write code that feels synchronous like other languages).

 

 
  [ # 2 ]

Go by Example: Timeouts

Implementing timeouts in Go is easy and elegant thanks to channels and select.

Reference: https://gobyexample.com/timeouts

 

 
  login or register to react