An action is what a block can do when it is executed with Typebot. A block can have multiple actions.
Here is the sendMessage
action of the Telegram block:
import { createAction, option } from '@typebot.io/forge'
import { auth } from '../auth'
import { got } from 'got'
export const sendMessage = createAction({
auth,
name: 'Send message',
options: option.object({
chatId: option.string.layout({
label: 'Chat ID',
placeholder: '@username',
}),
text: option.string.layout({
label: 'Message text',
input: 'textarea',
}),
}),
run: {
server: async ({ credentials: { token }, options: { chatId, text } }) => {
try {
await got.post(`https://api.telegram.org/bot${token}/sendMessage`, {
json: {
chat_id: chatId,
text,
},
})
} catch (error) {
console.log('ERROR', error.response.body)
}
},
},
})
Props
If the block requires authentication, the auth object needs to be passed to
the action.
If the block has options defined (see block props), this
needs to be provided here.
The action configuration options. See Options for more
information.
Check out the Run documentation for more information on how this can be configured depending of your scenario.
The function to execute on the server when the block is triggered. See
Run for more information.
getStreamVariableId
(options) => string | undefined
A function that returns the variable ID to stream.
The function to execute to stream the variable.
displayEmbedBubble
(options) => string | undefined
getSaveVariableId
(options) => string | undefined
A function that returns the variable ID to save as the result of the waitForEvent
function.
A function that parses the function to execute on the client. See Client function for more information.