
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
For chat-like conversation UI
import createBot from 'tchatche'
import { BotConfig } from 'tchatche/dist/types'
const config: BotConfig = {
// see below
}
const bot = createBot(config)
bot.on('end', ({ conversation, data }) => {
})
This is a simple example chat. The bot asks the user for her name (id: name). The conversation always starts with the first message. When the user puts in her name, we validate the input. In this case, we are just checking if the string is at least 2 characters long. If it is, we go over to a question where the user answers by clicking one of two buttons (id: one-or-two). If the name is not valid we go to name-validation-error where the user is asked to enter her name again. The conversation ends when one-or-two has been answered. The .on('end') callback is triggered. It returns the whole conversation and the data collected. In this case the data will look somthing like: { name: 'Xxxx', choice: 'two' }.
import createBot from 'tchatche'
import { BotConfig } from 'tchatche/dist/types'
const config: BotConfig = {
container: document.body,
messages: [
{
id: 'name',
botSays: () => ([
'Hello',
'What is your name?'
]),
userAction: {
inputType: 'input',
onSubmit: async (name: string) =>
name.length >= 2
? { nextMessageId: 'one-or-two', data: { property: 'name', value: name } }
: { nextMessageId: 'name-validation-error', data: { property: 'name', value: name } }
},
},
{
id: 'name-validation-error',
botSays: () => ([
'That is not your name',
'Seriously...',
'What is your name?',
]),
userAction: {
inputType: 'input',
onSubmit: async (name: string) =>
name.length >= 2
? { nextMessageId: 'one-or-two', data: { property: 'name', value: name } }
: { nextMessageId: 'name-validation-error', data: { property: 'name', value: name } }
},
},
{
id: 'one-or-two',
botSays: (data: any) => ([
`Thanks, ${data.name}`,
'Choose one or two',
]),
userAction: {
inputType: 'buttons',
buttons: [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' },
],
onSubmit: async ({ value, label }) =>
({ isEnd: true, data: { property: 'choice', value, label } })
},
}
]
}
const bot = createBot(config)
bot.on('end', ({ conversation, data }) => {
console.log('done', { conversation, data })
})
config objectexport interface BotConfig {
container: HTMLElement
messages: BotMessage[]
pace?: number
}
container is the element to which you want to add the chat.pace is the speed at which the bot is writing messages. 500 (ms) by default.messages is an array of "pages".messageexport interface BotMessage {
id: string
botSays: (data: any) => string[]
userAction: UserAction
}
id is used as a reference to get to that particular message in the flow. Must be unique.botSays is a function that takes data as an argument and returns an array of strings. data contains the values previously collected.userAction describes what the user can do after the bot has talked.userActionexport interface UserActionInput {
inputType: 'input'
placeholder?: string
onSubmit: (userInput: string, data: object, setData: (property: string, value: any) => void) => OnSubmitResponse
}
export interface Button {
label: string
value: string
}
export interface UserActionButton {
inputType: 'buttons'
buttons: Button[]
onSubmit: (button: Button, data: object, setData: (property: string, value: any) => void) => OnSubmitResponse
}
export type UserAction = UserActionInput
| UserActionButton
At the moment there are only two possible user actions:
The onSubmit function is triggered when the user has either clicked a button or pressed enter in an input and has the following arguments:
data collected so fardata (useful for temporary data that needs to be passed between messages)onSubmit responseonSubmit has to be an async function returning a OnSubmitResponse
export interface OnSubmitData {
nextMessageId: string
data: { property: string, value: string, label?: string }
}
export interface OnSubmitEnd {
data: { property: string, value: string, label?: string }
isEnd: true
}
export type OnSubmitResponse = Promise<OnSubmitData | OnSubmitEnd>
It either redirects to another message or ends the conversation. In both cases it has to return the data collected from the user.
FAQs
Conversation bot framework
The npm package tchatche receives a total of 25 weekly downloads. As such, tchatche popularity was classified as not popular.
We found that tchatche demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.