Configurar integração com o Telegram usando o plugin discourse-chat-integration

Este howto descreve como configurar o provedor Telegram incluído em discourse-chat-integration.

Habilitar o plugin

O plugin discourse-chat-integration é fornecido com o Discourse. Se ainda não o fez, siga as instruções principais do plugin para ativá-lo.

Configurar o Telegram

  1. Fale com o BotFather do Telegram :robot: e configure um novo bot. Instruções detalhadas aqui
  2. Certifique-se de copiar o token que o BotFather lhe dá. Ele será algo parecido com isto:
    110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
    

Configurar o Discourse

  1. Nas configurações do seu site, cole o token que você obteve anteriormente na configuração chat integration telegram access token (token de acesso do telegram para integração de chat) e salve.

  2. Ative a configuração chat_integration_telegram_enabled e salve.

  3. Vá para a aba Plugins, depois Chat Integrations (Integrações de Chat)

  4. Vá para a aba Telegram

    • Nota: se a aba Telegram não estiver visível, significa que algo deu errado ao conectar-se à API deles. Você deve verificar os logs do seu site e tentar novamente reativando a configuração chat_integration_telegram_enabled.

Adicionando um canal

  1. Adicione seu bot a um chat em grupo no Telegram (ou apenas inicie um chat privado com ele)

  2. Envie qualquer mensagem para o bot (ou para o chat em grupo onde o bot foi adicionado). Você deve receber uma mensagem com o Chat ID. Você também pode enviar uma mensagem começando com /getchatid.

  3. Copie o Chat ID. Se houver um sinal de menos antes dele, certifique-se de incluí-lo - é muito importante!

  4. Vá para o seu painel de administração do Discourse, Plugins, Chat Integrations, Telegram

  5. Clique em Add Channel (Adicionar Canal)

  6. Digite um nome para o canal (isso é exibido apenas no painel de administração do Discourse, pode ser qualquer coisa)

  7. Cole o Chat ID de antes na caixa e clique em Save Channel (Salvar Canal)

  8. Use o botão Test (Testar) no canal que você acabou de criar para verificar se tudo está funcionando. Você deverá ver algo assim:

  9. Configure algumas “Regras” para o seu canal, de acordo com as instruções do discourse-chat-integration.

  10. Aproveite todas as notificações :allthethings:

Usando em um canal de transmissão

Para enviar notificações para um canal de transmissão do Telegram, adicione o bot como administrador do canal e, em seguida, envie a mensagem

/getchatid

para obter o ID do chat. Em seguida, siga as instruções acima para configurar no Discourse. Para canais públicos, você também pode usar o formato @nomedocanal (por exemplo, @meuforumcanal) em vez do chat ID numérico.

Em um canal de transmissão, você não pode usar comandos de barra para gerenciar regras.

Comandos de barra (Slash commands)

Você pode usar “comandos de barra” para controlar regras a partir do Telegram. Verifique se a configuração do site chat integration telegram enable slash commands (habilitar comandos de barra para integração de chat do telegram) está ativada. Note que isso dá a qualquer pessoa que possa postar no chat em grupo a permissão para editar as regras.

Para aprender a usá-los, basta enviar /help (ou /help@meu-forum-bot se estiver em um chat em grupo) e o bot enviará uma mensagem de ajuda.

Configurando o auto-complete de comandos (não é necessário, mas facilita muito o uso)

  1. Fale com o BotFather do Telegram :robot:
  2. Selecione seu bot, clique em edit bot (editar bot) e depois em edit commands (editar comandos)
  3. Copie e cole esta lista de comandos
    watch - [category] [tag:name] | notificar este canal para novos tópicos e novas respostas que correspondam à regra
    follow - [category] [tag:name] | notificar este canal para novos tópicos que correspondam à regra
    mute - [category] [tag:name] | bloquear notificações para este canal para posts que correspondam à regra
    remove - [rule number] | remover uma regra (veja /status para os números)
    status - listar todas as regras para este canal
    help - exibir uma mensagem de ajuda
    
  4. Você deverá receber uma mensagem de sucesso :slight_smile:

Outras personalizações do bot

Fale com o BotFather do Telegram :robot: para personalizar o nome, descrição e ícone do seu bot. Você deve deixar a “Group Privacy” (Privacidade de Grupo) ativada, caso contrário, o bot tentará responder a cada mensagem em um chat em grupo.

27 curtidas

Isn’t possible to allow users to subscribe to any public category? Without asking an admin to add their id to the whitelist?

1 curtida

Not currently. It is possibly something that could be added (this is how Slack works), but given there is no concept of “organisations” on telegram, we would need to be careful that only public-facing categories are visible.

For per-user stuff you could try the telegram-notifications-plugin

1 curtida

But that means two different bots :sweat_smile:
Anyway, thanks for such good plugins :+1:

1 curtida

I’ve set it up, and it works with bot itself. However, when I set it up for public channel and try to test, an error “422 No Reason Phrase” occurs.
Could someone help me out?

Where does this error occur? In telegram, or in the “test” dialog in the Discourse admin panel?

Hi! I don’t see any submenu in the admin panel to manage Telegram settings

But i got my chat ID through the bot.

Hello,
Can you tell me what different Telegram notifications using the discourse-chat-integration plugin and Telegram Notifications Plugin (discourse-telegram-notifications)

Check the very top of this topic: Telegram Notifications Plugin (discourse-telegram-notifications) (the part with the :warning: next to it)

2 curtidas

Whenever ppl reply the telegram bot message, it keeps informing the current chat id, telling ppl to configure something different on the admin panel.

I have the actual msg in portuguese:

Este chat está configurado WTTD Fórum. Configure-o no painel de administração. (ID do bate-papo:-1001093143218)

Google translated:

This chat is configured WTTD Forum. Configure it in the administration panel. (Chat ID: -1001093143218)

It’s quite annoying.

Also I’ve disabled chat integration telegram enable slash commands however still replies the command list.

Is there a way to make the bot ignore any reply?

where can we Add the channel in discourse? we don’t find nothing… caht bot is active and we get also the Chat-ID, thanks in advance

1 curtida

After enabling the telegram site settings, head to your admin panel, click “plugins” at the top, then “chat integration” on the left.

3 curtidas

Hello, i don’t know is it ok right now, but after setting up bot in admin and adding bot to channel nothing happened.

Did you try using the “test channel” button. Did you get any errors?

1 curtida

test channel button works, but i expect ‘welcome’ message like in guide.

I’m not sure which guide you are talking about. The chat-integration plugin doesn’t send a welcome message.

Once you have configured the channel, you need to add some “rules”. Then, topics/posts you make on your discourse forum will appear in Telegram.

1 curtida

Estou falando sobre esta instrução.

1 curtida

Ah, I see. Try sending a message in the group, including the bot’s username (like @myforumbot). Then it should respond with that message.

3 curtidas

I’ve configured everything successfully, except that whenever a new member leaves/adds into the telegram group which has the ‘chat integration bot’ as one of this groups member, I receive this msg in the telegram group:

New rule: /[watch|follow|mute] [category] [tag:name]
(you must specify a rule type and at least one category or tag)

  • watch – notify this channel for new topics and new replies
  • follow – notify this channel for new topics
  • mute – block notifications to this channel

Remove rule: /remove [rule number]
([rule number] can be found by running /status)

List rules: /status

Help: /help

This msg has started irritating every time a member is added or removed into/from the telegram group.
And if I create a telegram broadcast/channel and add the chat integration bot into that, this problem doesn’t arise therein.