{"id":20547276,"url":"https://github.com/theopenconversationkit/tock-node","last_synced_at":"2025-04-14T10:33:24.657Z","repository":{"id":37413162,"uuid":"208287565","full_name":"theopenconversationkit/tock-node","owner":"theopenconversationkit","description":"Tock client to build conversational stories using Nodejs.","archived":false,"fork":false,"pushed_at":"2024-09-25T17:34:51.000Z","size":199,"stargazers_count":8,"open_issues_count":11,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-27T23:41:55.699Z","etag":null,"topics":["ai","bot","chatbot","nodejs","opensource","tock","typescript"],"latest_commit_sha":null,"homepage":"https://doc.tock.ai","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theopenconversationkit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-13T15:00:53.000Z","updated_at":"2024-09-25T17:34:55.000Z","dependencies_parsed_at":"2022-08-18T03:10:14.075Z","dependency_job_id":null,"html_url":"https://github.com/theopenconversationkit/tock-node","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopenconversationkit%2Ftock-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopenconversationkit%2Ftock-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopenconversationkit%2Ftock-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theopenconversationkit%2Ftock-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theopenconversationkit","download_url":"https://codeload.github.com/theopenconversationkit/tock-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248862959,"owners_count":21173907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","bot","chatbot","nodejs","opensource","tock","typescript"],"created_at":"2024-11-16T02:07:14.079Z","updated_at":"2025-04-14T10:33:24.638Z","avatar_url":"https://github.com/theopenconversationkit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Dependencies](https://img.shields.io/librariesio/release/npm/tock-node)](https://img.shields.io/librariesio/release/npm/tock-node)\n\n[![Latest release](https://img.shields.io/npm/v/tock-node)](https://img.shields.io/npm/v/tock-node)\n[![Release Date](https://img.shields.io/github/release-date/theopenconversationkit/tock-node)](https://github.com/theopenconversationkit/tock-node/releases)\n[![NPM Downloads](https://img.shields.io/npm/dy/tock-node)](https://img.shields.io/npm/dy/tock-node)\n\n[![Gitter](https://badges.gitter.im/tockchat/Lobby.svg)](https://gitter.im/tockchat/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=body_badge)\n[![Contributors](https://img.shields.io/github/contributors-anon/theopenconversationkit/tock-node)](https://github.com/theopenconversationkit/tock-node/graphs/contributors)\n[![Commit Activity](https://img.shields.io/github/commit-activity/y/theopenconversationkit/tock-node)](https://github.com/theopenconversationkit/tock-node/pulse/monthly)\n\n[![Home](https://img.shields.io/website?label=home\u0026down_message=offline\u0026up_message=doc.tock.ai\u0026url=https%3A%2F%2Fdoc.tock.ai)](https://doc.tock.ai)\n[![Demo](https://img.shields.io/website?label=demo\u0026down_message=offline\u0026up_message=live\u0026url=https%3A%2F%2Fdoc.tock.ai)](https://doc.tock.ai)\n[![License](https://img.shields.io/github/license/theopenconversationkit/tock-node)](https://github.com/theopenconversationkit/tock-react-kit/blob/master/LICENSE)\n\n# Tock Node\n\n\u003cimg alt=\"Tock Logo\" src=\"http://doc.tock.ai/tock/en/assets/images/logo.svg\" style=\"width: 150px;\"\u003e\u003cbr\u003e\n\nA Nodejs framework to write stories in JS for a [Tock](https://doc.tock.ai) chatbot.\n\n🏠 Home: [https://doc.tock.ai](https://doc.tock.ai)\n\n💬 Contact: [https://gitter.im/tockchat/Lobby](https://gitter.im/tockchat/Lobby)\n\n## Prerequisites\n\n- Run a [Tock bot in API mode](https://doc.tock.ai/tock/en/dev/bot-api/)\n- Create a Bot application using the **web** connector type in Tock Studio and get your API key\n\n## Installation\n\n```\nyarn add tock-node\nnpm i tock-node\n```\n\n_The package has TypeScript type definitions_\n\n## Usage\n\n```js\nconst { Bot } = require('tock-node');\n\nconst bot = new Bot('\u003cTOCK_API_KEY\u003e', '\u003cTOCK_HOST\u003e', \u003cTOCK_WS_PORT\u003e, '\u003cTOCK_WS_PROTOCOL\u003e');\n\nbot.addStory('intent', bot =\u003e {\n  bot.send('Hello World!');\n});\n```\n\nDefault Tock platform host, port and WebSocket protocol are `demo-bot.tock.ai` (the public demo), \n`443` and `wss` (secured port/protocol).\n\nFor more examples, see [`tock-node-example`](https://github.com/theopenconversationkit/tock-node-example).\n\n### Sending messages\n\nYou can call `send` as many times as you need. All messages will be sent within the same response.\n\n```js\nbot.addStory('intent', bot =\u003e {\n  bot.send('Good morning!');\n  bot.send('How are you?');\n});\n```\n\n### Sending cards\n\nYou can use send to send other message templates such as cards.\n\n```js\nconst imageCard = require('tock-node').imageCard;\nconst action = require('tock-node').action;\n\nbot.send(imageCard('Card title', 'Card description', 'https://site/image.png', action('Button')));\n```\n\n### Sending carousels\n\nThere is also a template that lets you send multiple cards in a carousel.\n\n```js\nconst imageCard = require('tock-node').imageCard;\nconst action = require('tock-node').action;\n\nbot.send({\n  cards: [\n    imageCard('Card 1', '', 'https://site/image.png'),\n    imageCard('Card 2', '', 'https://site/image.png'),\n    imageCard('Card 3', '', 'https://site/image.png'),\n  ],\n});\n```\n\n### Quick replies\n\nQuick replies are highly buttons that are following a message. You can send quick replies following a message using `send`.\n\n```js\nconst suggestion = require('tock-node').suggestion;\n\nbot.send('Check this out!', suggestion('View Tock on GitHub'), suggestion(\"View Tock's Website\"));\n```\n\n### Get entities and using the original user request\n\nYou can get the original user request (containing his message) from the second argument of the story handler. This is also how you retrieve entities found by Tock.\n\n```js\nbot.addStory('intent', (bot, request) =\u003e {\n  // user message\n  console.log(request.message.text);\n  // entities\n  console.log(request.entities);\n});\n```\n\n### Manage user data/context\n\nEach user has a user context that is persistent across all stories. You can use it and also set it.\n\n```js\nbot.addStory('intent', bot =\u003e {\n  // getting user context\n  console.log(bot.userData);\n  // setting\n  bot.dispatchUserData({ firstName: 'Tockito' });\n});\n```\n\nIn the case of multiple dispatches you can retrieve the _current_ user data by using a callback function that uses the _current_ user data as an argument.\n\n```js\nbot.addStory('intent', bot =\u003e {\n  bot.dispatchUserData({ firstName: 'Foo' });\n  bot.dispatchUserData(userData =\u003e {\n    console.log(userData);\n    // {\"firstname\":\"Foo\"}\n    return { firstName: userData.firstName, lastName: 'Bar' };\n  });\n});\n```\n\n### Asynchronous stories\n\nIf you'd like to wait for an action before sending you can use a `Promise` as a callback to your story handler.\n\n```js\nbot.addStory('intent', async bot =\u003e {\n  const message = await fetchingData();\n  bot.send(message);\n});\n```\n\n### Chaining/reusable story handlers\n\nYou can add as many story handlers as you want in the same `addStory`.\n\n```js\nconst handler1 = bot =\u003e send('First handler');\nconst handler2 = bot =\u003e send('Second handler');\n\nbot.addStory('intentA', handler1, handler2);\nbot.addStory('intentB', handler1, handler2);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopenconversationkit%2Ftock-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheopenconversationkit%2Ftock-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheopenconversationkit%2Ftock-node/lists"}