Forms: How to send notifications about new submissions to Telegram

Based on the insights from this thread (kudos to @Sina and @Aleksandr_Popov) , we’ve created a simple guide on how to send notifications for new form submissions to Telegram :raising_hands:

Register your Telegram Bot
  • First, open BotFather on Telegram. You can find it by searching for “BotFather” in the Telegram search bar.

  • Start a chat with BotFather and type /newbot to create a new bot.

  • BotFather will ask you for two things:

    • Bot name: This is the display name of your bot.
    • Bot username: This should be unique and end with “bot” (e.g., MyAwesomeBot).
  • After providing this information, BotFather will generate a bot token. Keep this token handy, as you’ll use it to interact with your bot programmatically


Get a Telegram Channel ID

To send messages from your bot, you need to know the Telegram Chat ID of the user you want to message. For this, use another bot called userinfobot.

  • Open the Telegram search bar, type userinfobot, and start a conversation with it.
  • Click Start, and the bot will send you your Telegram ID. This is the ID you’ll use to send messages to yourself or another user:


Once you have the bot token and the user ID, you’re ready to create a form and start sending messages from your bot :wink:


Adding a custom code

Here is a custom code to send notifications about new submissions to your Telegram channel:

const TELEGRAM_BOT_TOKEN = 'YOUR_TOKEN';
const TELEGRAM_CHAT_ID = 'CHAT_ID';

widget.on('submit', (fields) => {
	let text = '';
	Object.values(fields).forEach((field) => {
		if (field.value && field.type !== 'consent') {
			text += `${field.name}: ${field.value}\n`;
		}
	});

	fetch(`https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage`, {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json',
		},
		body: JSON.stringify({
			chat_id: TELEGRAM_CHAT_ID,
			text,
		}),
	}).catch(() => {
		console.error(`Form: the message wasn't sent to Telegram.`);
	});
});

Replace YOUR_TOKEN and CHAT_ID with your Telegram Bot Token and Chat ID and add the resulted code to the Custom JS field on the Settings tab of your Form widget’s settings.


Voila! Now you’ll receive notifications about new form submissions in your Telegram Channel:


Folks, was the solution helpful to you? Let us know in the comments :wink:

2 Likes