Full API reference for Cord's base chatbot SDK, npm package @cord-sdk/chatbot-base
This page is a detailed reference of the base chatbot SDK. For a beginner's overview of how this all fits together, see our Getting Started document, which includes chatbot example code.
In order to define a Chatbot
object, you'll need to specify the following properties and methods:
This is an object with the following fields:
Show property details
if (eventIsFromBot(event)) return false
so that the bot does not get stuck in a loop responding to itself.true
, getResponse
will later be called to actually compute the response. If false
, then getResponse
will be entirely skipped.This is an object with the following fields:
Show property details
string
, or as a Promise
which resolves to a string. You can also return an AsyncIterator
which yields the message incrementally; the message will be streamed to Cord and appear on users' screens bit-by-bit as the iterator yields it (with the final message being the concatenation of all of the strings yielded). Can also return null
or undefined
to signal that no new message should be added (but it is better for performance to return false
from shouldRespondToEvent
instead).This is an array of objects, each of which has the following fields:
Show property details
This is an object with the following fields:
Show property details
getResponse
has finished sending a new message to Cord, with the contents of that message. This can occasionally be useful when you need to do something with the completed Cord message, such as setting metadata
on the message. You might also use this callback in a complex game in order to call forceRespond
to cause a different AI to continue the conversation!getResponse
. The message structure is the same as returned by the message REST API.This is an object with the following fields:
Show property details
getResponse
, so it will not include the response
message. The message structure is the same as returned by the message REST API.This is an array of objects, each of which has the following fields:
Show property details
This is an object with the following fields:
Show property details
To create a new ChatbotRegistry
, you'll need your Cord project ID and project secret from the Cord console. Then you can call chatbots(project_id, project_secret)
to create a new registry. You'll typically do this only once, at server startup.
The resulting registry has the following methods you can call on it:
Chatbot
object to register.This is an object with the following fields:
Show property details
true
, that means that this function has fully handled the webhook and you should respond to the HTTP request with success. If that boolean is false
, then this function didn't handle the webhook; you can either handle the webhook yourself (e.g., if you have other uses for Cord webhooks beyond chatbots) or otherwise return an HTTP failure code.Request
object received by the webhook HTTP POST handler.shouldRespondToEvent
and move directly to getResponse
. This is useful if you want a bot to start a conversation unprompted, for example.The SDK provides a couple of small utility functions to help write your chatbot logic.
shouldRespondToEvent
to make sure that a bot does not respond to itself.true
if that message was sent by a bot, false
otherwise.This is an object with the following fields:
Show property details
Not finding the answer you need? Ask our Developer Community