---
title: Action
---

An action is what a block can do when it is executed with Typebot. A [block](./block) can have multiple actions.

Here is the `sendMessage` action of the Telegram block:

```ts
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)
      }
    },
  },
})
```

<Frame>
  <img src="/images/contribute/action-example.png" alt="Action example" />
</Frame>

## Props

<ResponseField name="name" type="string" required>
  The name of the action.
</ResponseField>

<ResponseField name="auth" type="Auth">
  If the block requires authentication, the auth object needs to be passed to
  the action.
</ResponseField>

<ResponseField name="baseOptions" type="z.ZodObject<any>">
  If the block has options defined (see [block props](./block#props)), this
  needs to be provided here.
</ResponseField>

<ResponseField name="options" type="z.ZodObject<any>">
  The action configuration options. See <a href="./options">Options</a> for more
  information.
</ResponseField>

<ResponseField name="run">
  Check out the <a href="./run">Run</a> documentation for more information on how this can be configured depending of your scenario.
  <Expandable title="properties">
    <ResponseField name="server" type="ServerRunFunction">
      The function to execute on the server when the block is triggered. See{' '}
      <a href="./run">Run</a> for more information.
    </ResponseField>
    <ResponseField name="stream">
      <Expandable title="properties">
        <ResponseField
          name="getStreamVariableId"
          type="(options) => string | undefined"
        >
          A function that returns the variable ID to stream.
        </ResponseField>
        <ResponseField name="run" type="StreamRunFunction">
          The function to execute to stream the variable.
        </ResponseField>
      </Expandable>
    </ResponseField>
    <ResponseField name="web">
      <Expandable title="properties">
        <ResponseField
          name="displayEmbedBubble"
          type="(options) => string | undefined"
        >
          <Expandable title="properties">
            <ResponseField
              name="parseInitFunction"
              type="WebFunctionParser"
            >
              See <a href="./run#client-function">Client function</a> for more information.
            </ResponseField>
            <ResponseField name="waitForEvent">
              <Expandable title="properties">
                <ResponseField
                  name="getSaveVariableId"
                  type="(options) => string | undefined"
                >
                  A function that returns the variable ID to save as the result of the `waitForEvent` function.
                </ResponseField>
                <ResponseField name="parseFunction" type="WebFunctionParser">
                  See <a href="./run#client-function">Client function</a> for more information.
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>
        <ResponseField name="parseFunction" type="WebFunctionParser">
          A function that parses the function to execute on the client. See <a href="./run#client-function">Client function</a> for more information.
        </ResponseField>
      </Expandable>

    </ResponseField>

  </Expandable>
</ResponseField>
