Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

How to detect if client disconnects from chatbot? #59

Open
hadizainudin opened this issue Apr 18, 2019 · 2 comments
Open

How to detect if client disconnects from chatbot? #59

hadizainudin opened this issue Apr 18, 2019 · 2 comments

Comments

@hadizainudin
Copy link

Hello there. I have created a Botkit Chatbot, and embedded it on a page, passing current date and time, and cookies.

<div id="embedded_messenger">
  <header id="message_header" onclick="Botkit.toggle()">My Chatbot</header>
  <iframe id="botkit_client" src="//{{base_url}}/chat.html"></iframe>
</div>
<script src="//{{base_url}}/embed.js"></script>
<link rel="stylesheet" href="//{{base_url}}/css/embed.css" />
<script>
  Botkit.boot({ id: new Date().getTime(), name: Botkit.getCookie("myCookie") });
</script>

Then, it would create a JSON file.

/components/plugin_identity.js, line 34 to 36

controller.storage.users.save(user, function (err) {
  next();
});

/.data/db/users/1555557850438.json

{
  "id": "1555557850438",
  "attributes": {
    "timezone_offset": -480
  },
  "name": "user_0123",
}

What I wanted to do now is:

  1. I wanted to detect if client fully disconnects. How do I do that?
  2. If client is fully disconnects, I wanted to delete created file for that session. Maybe I call fs.unlink or controller.storage.channels.delete? Still thinking of how to achieve this.

Thank you for your time, and have a nice day.

@benbrown
Copy link
Contributor

I would recommend replacing the built-in storage system with your own database-backed system. The built-in filesystem storage is only meant for "quick start" exploration.

Then, you could purge data out of your database based on a last modified timestamp or something like that.

@hadizainudin
Copy link
Author

I will try to do what I can.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants