# Telegram

URL: https://swb.one/es/docs/setup/telegram

SwB habla con Telegram a través de un bot que creas en BotFather. SwB consulta a Telegram si hay mensajes nuevos, así que tu servidor SwB puede seguir en una dirección privada.

## Antes de empezar [#antes-de-empezar]

Usa una cuenta de Telegram. Para conectar un grupo, usa una cuenta que pueda añadir miembros. Inicia sesión en SwB como propietario.

## Copiar el prompt de configuración [#copiar-el-prompt-de-configuración]

https://swb.one/prompts/telegram.md

```
Read the setup guide at https://swb.one/docs/setup/telegram.

Help me connect Telegram to SwB. SwB carries messages between my agents and channels.

If the SwB tools are missing, ask me to add SwB as a custom MCP server. Follow https://swb.one/docs/connect to add the client.

For Claude, give me the path `Customize > Connectors > Add > Custom > Web`. For ChatGPT, ask me to open `https://chatgpt.com/plugins`. Give me the path `+ > Add custom MCP server`. For Grok, give me the path `grok.com > Connectors > New Connector > Custom`. For other apps, ask me to open the MCP server settings. Wait for me to confirm.

Use a SwB client with owner access.

Call `connect(what="telegram")`. Do each step marked "you" yourself. Give me each step marked "person" one at a time with the exact click path and links. Wait for me to say done after each step.

Ask me to open https://t.me/BotFather and send `/newbot`. Ask me to choose the bot's name and username. BotFather replies with the token. Ask me to enter it only through the claim link from `connect`. Then ask me to start a chat with the bot and send one message.

For a group, ask me to open `setup.add_to_group_url` from `telegram_status`. Ask me to select the group. Ask me to send `/swb@<bot username>` there. To let the bot read all group messages, ask me to send `/setprivacy` to BotFather. Ask me to choose the bot and select **Disable**. Ask me to remove the bot from the group. Ask me to add it again.

Use `telegram_status` to get the chat IDs from `setup.seen_chats` and my user ID from the direct message. Add a space under `blocks.telegram.spaces` in `config/switchboard.yaml`. Put the chat IDs in `chats` and my user ID in `owner_ids`. Grant the test agent access in `blocks.telegram.agents`. If the file needs a manual edit, give me the YAML. Restart SwB after an edit.

Call `connect(what="telegram")` again to check the connection. When it reports `connected`, ask me to choose a test chat. Call `telegram_post` with the space label, chat ID and test text. Show me the result.

Subscribe to switchboard.message.created if this app supports MCP events. Otherwise, call wait or inbox to collect new messages.
```

Pega el prompt en tu cliente de propietario de SwB.

## Configurar el bot de Telegram [#configurar-el-bot-de-telegram]

### Abrir BotFather [#abrir-botfather]

Abre https://t.me/BotFather en Telegram. Toca **Start** si es tu primer chat con BotFather.
### Crear el bot [#crear-el-bot]

Envía `/newbot`. Responde con un nombre visible.

### Elegir el nombre de usuario [#elegir-el-nombre-de-usuario]

Responde con un nombre de usuario que termine en `bot`. BotFather responde con el token.
### Guardar el token [#guardar-el-token]

Abre el enlace de entrega de SwB que te da tu agente. Pega el token en el campo.
### Abrir un chat privado [#abrir-un-chat-privado]

Toca **Start** en el chat privado con tu bot. Envía un mensaje para que SwB encuentre tu ID de usuario.
### Añadir el bot a un grupo [#añadir-el-bot-a-un-grupo]

Abre el enlace de grupo que te da tu agente. Elige el grupo.

### Enviar el comando de configuración [#enviar-el-comando-de-configuración]

Envía `/swb@<bot username>` en el grupo. Así SwB conoce el ID del grupo.
### Leer todos los mensajes del grupo [#leer-todos-los-mensajes-del-grupo]

Para los grupos en los que el bot necesita todos los mensajes, envía `/setprivacy` a BotFather. Elige tu bot. Selecciona **Disable**.

### Añadir el bot de nuevo [#añadir-el-bot-de-nuevo]

Quita el bot de cada grupo. Añade el bot al grupo otra vez.

## Lo que hace el agente [#lo-que-hace-el-agente]

El agente llama a `connect(what="telegram")`. Si hace falta, activa el bloque `telegram`. Con el bloque activo, `connect` o `telegram_provision` devuelve un enlace de entrega para el token del bot.

Después de que guardes el token, el agente llama a `telegram_status`. Comprueba el bot y el modo de privacidad. La invitación al grupo está en `setup.add_to_group_url`. Los IDs de los chats recientes están en `setup.seen_chats`.

El agente configura un espacio en `blocks.telegram.spaces` dentro de `config/switchboard.yaml`. Un espacio asocia un conjunto de chats a un proyecto de SwB. Pon los IDs de los grupos en `chats`. Pon tu ID de usuario en `owner_ids`. Reinicia SwB después de editar el archivo.

## Credenciales [#credenciales]

| Token | Dónde lo muestra Telegram | Formato | Dónde va |
| --- | --- | --- | --- |
| Token del bot | Respuesta de BotFather tras `/newbot` o tras `/token` | Cifras, dos puntos y después letras y cifras | Enlace de entrega de SwB |

## Comprobar la conexión [#comprobar-la-conexión]

Pide al agente que llame a `connect` otra vez. Devuelve `connected` cuando la configuración está completa.

Usa la cuenta de Telegram que figura en `owner_ids`. Envía `/swb <target> hello` al bot en un chat privado. Cambia `<target>` por un nombre de destino de `targets`. Comprueba que llega una respuesta.

## Resolver problemas [#resolver-problemas]

Si en un grupo el bot solo lee comandos, desactiva el modo de privacidad en BotFather. Después quita el bot y añádelo de nuevo.

Un webhook es una dirección web a la que Telegram envía mensajes. Pide al propietario del bot que borre cualquier webhook antiguo con el método `deleteWebhook` de Telegram.
