Skip to main content

How to Post to Telegram Channel or Group from Google Form Submit

Post to Telegram Channel when a user submits a Google form by following the steps below.

To be able to post a Message programmatically to Telegram you will need two things , A Telegram Channel where you want to post and a Telegram Bot which will be used to post the message.Telegram Bot is a automated Telegram Account that uses software for various tasks.

  1. Create or use an Existing Bot:

    • BotFather is a telegram utility that allows you to manage your bot.
    • Open BotFather inside your telegram app and follow the onscreen instructions.
    • Type /start to start BotFather.
    • Type /newbot to create a newbot and follow the onscreen instructions to name it appropriately and complete the set up.
    • Once you create the Bot you will see a successful message with a token .This is your secret token and do not share it with anyone.

    Bot Creation

    For the Above image API key is 8084838317:AAECE7Ty3Ia23zAAvxuqfsLVnMyGmRuYB_c

    • This token will be used in a later step to configure Form Notify to post the message.
    • You can avoid this step if you already have an existing Bot and you want to use the same for posting message to a channel.
  2. Add Bot to Channel:

    • Open the Channel where you want to post message.
    • Under Members section tap on "Administrators"
    • Click on "Add Admin" , search for the newly created Bot in the above step and add the bot as an Administrator.
    • This is required because The Bot has to have Administrator priviledge to be able to post a message.
  3. Find Channel Id:

    • We need to find the Channel id to be able to send a message to the Channel programmatically.
    • Post a Test Message to the channel if the Channel is new and doesnt have any Message.
    • Construct the below URL in the format and open it in browser. -https://api.telegram.org/bot<BOT Secret Key Goes Here>/getUpdates
    • Please use the Bot secret key received in step 1 in the above URL.
    • When you paste the URL in the browser , you will get some response that will look like the following .
      "sender_chat": {
      "id": -1002334996980,
      "title": "Test Webhook",
      "type": "channel"
      },
    • Please note down the value of "id" from the message you see in browser.In my case this id was -1002334996980
    • This is the unique Id of your channel.
  4. Create a WebHook in Form Email Notifications:

    • Open the Form Email Notifications add-on and click on "Setup Webhooks."
    • Click on "Add Webhook" to create a new Webhook.
    • Fill in the following fields in the Webhook creation window:
      • Webhook Name: Telegram Integration (You may also postfix your bot name for easier identification later )
      • URL: The URL is of the format https://api.telegram.org/bot<<Bot Secret Goes Here>>/sendMessage
      • Request Method: Select POST.
      • Headers: Leave as is with a default header (Content-Type: application/json).
      • Request Body: Use the following JSON template:
        {"chat_id": "-1002334996980", "text": "You have received a new response for Google form <{{ Form Publish Url }}| {{ Form Name }}>"}
        Please replace your Chat id obtained in the previous step.
      • You can refer https://telegram-bot-sdk.readme.io/reference/sendmessage for all the other parameters in the message.
    • Click on Save to create your webhook.
  5. Test Your Webhook:

    • You can test the webhook before saving by clicking the "Test" button on the Webhook Editor Window.
    • If you receive a status code as 200, it means your test was successful.
    • You can also check your Telegram Channel to see if the message was posted successfully
  6. Submit the Google Form:

    • Open the Google form preview by clicking on the Preview button on the top right of the Google form window.
    • Submit the form, and if everything is configured correctly, you should receive a notification in your Slack channel.
note

The process to create webhook and the json format may have changed after this page was written . Please check Telegram developer document for more details.