Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tock client to build conversational stories using Nodejs.

License

NotificationsYou must be signed in to change notification settings

theopenconversationkit/tock-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dependencies

Latest releaseRelease DateNPM Downloads

GitterContributorsCommit Activity

HomeDemoLicense

Tock Node

Tock Logo

A Nodejs framework to write stories in JS for aTock chatbot.

🏠 Home:https://doc.tock.ai

💬 Contact:https://gitter.im/tockchat/Lobby

Prerequisites

  • Run aTock bot in API mode
  • Create a Bot application using theweb connector type in Tock Studio and get your API key

Installation

yarn add tock-nodenpm i tock-node

The package has TypeScript type definitions

Usage

const{ Bot}=require('tock-node');constbot=newBot('<TOCK_API_KEY>','<TOCK_HOST>',<TOCK_WS_PORT>, '<TOCK_WS_PROTOCOL>');bot.addStory('intent', bot =>{bot.send('Hello World!');});

Default Tock platform host, port and WebSocket protocol aredemo-bot.tock.ai (the public demo),443 andwss (secured port/protocol).

For more examples, seetock-node-example.

Sending messages

You can callsend as many times as you need. All messages will be sent within the same response.

bot.addStory('intent',bot=>{bot.send('Good morning!');bot.send('How are you?');});

Sending cards

You can use send to send other message templates such as cards.

constimageCard=require('tock-node').imageCard;constaction=require('tock-node').action;bot.send(imageCard('Card title','Card description','https://site/image.png',action('Button')));

Sending carousels

There is also a template that lets you send multiple cards in a carousel.

constimageCard=require('tock-node').imageCard;constaction=require('tock-node').action;bot.send({cards:[imageCard('Card 1','','https://site/image.png'),imageCard('Card 2','','https://site/image.png'),imageCard('Card 3','','https://site/image.png'),],});

Quick replies

Quick replies are highly buttons that are following a message. You can send quick replies following a message usingsend.

constsuggestion=require('tock-node').suggestion;bot.send('Check this out!',suggestion('View Tock on GitHub'),suggestion("View Tock's Website"));

Get entities and using the original user request

You 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.

bot.addStory('intent',(bot,request)=>{// user messageconsole.log(request.message.text);// entitiesconsole.log(request.entities);});

Manage user data/context

Each user has a user context that is persistent across all stories. You can use it and also set it.

bot.addStory('intent',bot=>{// getting user contextconsole.log(bot.userData);// settingbot.dispatchUserData({firstName:'Tockito'});});

In the case of multiple dispatches you can retrieve thecurrent user data by using a callback function that uses thecurrent user data as an argument.

bot.addStory('intent',bot=>{bot.dispatchUserData({firstName:'Foo'});bot.dispatchUserData(userData=>{console.log(userData);// {"firstname":"Foo"}return{firstName:userData.firstName,lastName:'Bar'};});});

Asynchronous stories

If you'd like to wait for an action before sending you can use aPromise as a callback to your story handler.

bot.addStory('intent',asyncbot=>{constmessage=awaitfetchingData();bot.send(message);});

Chaining/reusable story handlers

You can add as many story handlers as you want in the sameaddStory.

consthandler1=bot=>send('First handler');consthandler2=bot=>send('Second handler');bot.addStory('intentA',handler1,handler2);bot.addStory('intentB',handler1,handler2);

About

Tock client to build conversational stories using Nodejs.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors6


[8]ページ先頭

©2009-2026 Movatter.jp