How to send to all bot subscribers in Telegram?

Hi!

I reproduced https://www.youtube.com/watch?v=Tv2eT0CxoP4. I wonder if it’s possible to send a message (say, from email trigger) to all users that subscribed to telegram chat bot?

Hi @ycomb,

To send a message to all users subscribed to a Telegram chat bot when you receive a new email, you’ll need to set up a Pipedream workflow with the Email trigger and a Telegram action.

  1. Create a new workflow and search for the Email app in the trigger menu.
  2. Select the “New Email” trigger and connect your Email account.
  3. Follow the instructions on the trigger configuration screen.

Next, you’ll need to add a Telegram action to send the message:

  1. Search for the Telegram app in the step menu.
  2. Select the “Send Message” action and connect your Telegram account.
  3. Configure the action with the chat ID of the users you want to send the message to, and set the message text using the data from the Email trigger.

Please note that you’ll need to have the chat IDs of the users who have subscribed to your Telegram chat bot. You can store these chat IDs in an array and loop through them to send the message to each user.

If you need more help or have any questions, feel free to ask.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

1 Like

Does pipedream have global storage where I cat put user chat id once he/she subscribed?

How to put array of chat ids to Chat ID field?

Cc @pi

@ycomb you can use Pipedream Datastore

1 Like

Hi @ycomb,

Yes, Pipedream has a key-value store called Datastore that you can use to store and manage user chat IDs. You can store an array of chat IDs and retrieve them when needed. Here’s an example of how to store and retrieve chat IDs using Pipedream Datastore:

  1. To store an array of chat IDs, you can use the following code in a Pipedream code step:
const chatIds = [12345, 67890]; // Replace this with the actual chat IDs
await $store.set("chatIds", chatIds);
  1. To retrieve the stored chat IDs, use the following code in another code step:
const chatIds = await $store.get("chatIds");

Now you can use the chatIds array to send messages to all subscribed users.

Regarding sending a message to all users subscribed to a Telegram chat bot when you receive a new email, you can set up a Pipedream workflow with the Email trigger and a code step to loop through the chat IDs and send messages using the Telegram Bot API. Here’s an example:

  1. Create a new workflow and search for the Email app in the trigger menu.
  2. Select the “New Email” trigger and connect your Email account.
  3. Follow the instructions on the trigger configuration screen.

Next, add a code step to send the message to all users:

const chatIds = await $store.get("chatIds");
const messageText = `New email from ${steps.trigger.event.from}: ${steps.trigger.event.subject}`;

const sendTelegramMessage = async (chatId) => {
  await axios(this, {
    method: "POST",
    url: `https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage`,
    data: {
      chat_id: chatId,
      text: messageText,
    },
  });
};

for (const chatId of chatIds) {
  await sendTelegramMessage(chatId);
}

Replace <YOUR_BOT_TOKEN> with your actual Telegram bot token. This code step will loop through the stored chat IDs and send a message to each user with the email details.

If you need more help or have any questions, feel free to ask.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

@pi does pipedream or telegram have any limits to the amount of users or messages I might send?

Hi @ycomb,

Pipedream has its own rate limits and usage quotas based on the plan you’re on. You can find the details at https://pipedream.com/pricing. As for Telegram, they also have their own rate limits and restrictions. You can find more information on Telegram’s rate limits in their Bot API documentation.

Please note that you should always check the respective platforms’ documentation for the most up-to-date information on rate limits and usage quotas.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

@pi explain exactly the same with examples in Python

Hi @ycomb,

To send a message to all users subscribed to a Telegram chat bot when you receive a new email, you can create a Pipedream workflow with the Email trigger and a Telegram action.

  1. Create a new workflow and search for the Email app in the trigger menu.
  2. Select the “New Email” trigger and connect your Email account.
  3. Follow the instructions on the trigger configuration screen.

Next, you’ll need to add a Telegram action to send the message:

  1. Search for the Telegram app in the step menu.
  2. Select the “Send Message” action and connect your Telegram account.
  3. Configure the action with the chat ID of the users you want to send the message to, and set the message text using the data from the Email trigger.

Please note that you’ll need to have the chat IDs of the users who have subscribed to your Telegram chat bot. You can store these chat IDs in an array and loop through them to send the message to each user.

If you need more help or have any questions, feel free to ask.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.