Is it Possible to Only Forward Media Within a Telegram Group?

This topic was automatically generated from Slack. You can find the original thread here.

Please can somebody tell me if it is possible to just forward media within a telegram group?

yes it is possible

Do you know if there are any guides for this? I am a total newb

Hi, I think your question is a great case for Pipedream bot to help. I’ll pass your question to the Pipedream bot now. Please feel free to ask it any question

can you help?

Of course! I can help you with forwarding media within a Telegram group using Pipedream. To achieve this, you’ll need to create a workflow with a Telegram Bot as the trigger and an action to forward the media to the desired group. First, you’ll need to create a Telegram bot if you haven’t already. You can follow the instructions here: Bots: An introduction for developers Once you have your bot and its API token, follow these steps: 1. Create a new Pipedream workflow. 2. Add a Telegram Bot trigger to your workflow and connect it with your bot’s API token. 3. Add a Node.js code step to your workflow and use the following code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { telegramBot: { type: "app", app: "telegram_bot", }, targetGroup: { type: "string", label: "Target Group Chat ID", }, }, async run({ steps, $ }) { const { message } = steps.trigger.event; const { chat, message_id } = message; if (message.photo || message.video || message.document) { return await axios($, { method: "POST", url: `https://api.telegram.org/bot${this.telegramBot.$auth.bot_token}/forwardMessage`, data: { chat_id: this.targetGroup, from_chat_id: chat.id, message_id: message_id, }, }); } else { console.log("No media found in the message."); } }, }); 4. Replace the telegramBot prop with your Telegram bot app and enter the target group’s chat ID in the targetGroup prop. Now, whenever your bot receives a message containing media (photo, video, or document), it will forward the media to the specified Telegram group. If you need further assistance, please let me know!

Holy shit that’s op cheers man

can this be done to forward telegram media to a specific discord channel?

Yes, you can forward Telegram media to a specific Discord channel using Pipedream. You’ll need to modify the previous workflow I provided and add a Discord action to send the media to the desired channel. Here’s how you can do it: 1. Follow the steps from the previous answer to set up the Telegram part of the workflow. 2. Add a new action to your workflow by searching for the Discord app in the step menu. 3. Select the “Send Message With File” action. 4. Connect your Discord account. 5. Configure the action by selecting the desired Discord channel and passing the media URL from the Telegram message. You can access the media URL from the Telegram message object like this: steps.previous_step_name.data.photo[0].file_path (replace previous_step_name with the name of the previous step). Here’s the modified code for the Telegram part of the workflow: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { telegramBot: { type: “app”, app: “telegram_bot”, }, targetGroup: { type: “string”, label: “Target Group Chat ID”, }, }, async run({ steps, $ }) { const { message } = steps.trigger.event; const { chat, message_id } = message; if (message.photo || message.video || message.document) { const response = await axios($, { method: “POST”, url: https://api.telegram.org/bot${this.telegramBot.$auth.bot_token}/getFile, data: { file_id: message.photo ? message.photo[0].file_id : message.video ? message.video.file_id : message.document.file_id, }, }); const file_path = response.data.result.file_path; const file_url = https://api.telegram.org/file/bot${this.telegramBot.$auth.bot_token}/${file_path}; return { chat_id: chat.id, message_id: message_id, file_url: file_url }; } else { console.log(“No media found in the message.”); } }, });

please condense this into one guide to avoid confusion

Sure, here’s a condensed guide on how to forward Telegram media to a specific Discord channel using Pipedream: 1. Create a new Pipedream workflow. 2. Add a Telegram Bot trigger and connect it with your bot’s API token. 3. Add a Node.js code step with the following code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { telegramBot: { type: "app", app: "telegram_bot", }, }, async run({ steps, $ }) { const { message } = steps.trigger.event; const { chat, message_id } = message; if (message.photo || message.video || message.document) { const response = await axios($, { method: "POST", url: `https://api.telegram.org/bot${this.telegramBot.$auth.bot_token}/getFile`, data: { file_id: message.photo ? message.photo[0].file_id : message.video ? message.video.file_id : message.document.file_id, }, }); const file_path = response.data.result.file_path; const file_url = `https://api.telegram.org/file/bot${this.telegramBot.$auth.bot_token}/${file_path}`; return { chat_id: chat.id, message_id: message_id, file_url: file_url }; } else { console.log("No media found in the message."); } }, }); 4. Add a Discord “Send Message With File” action, connect your Discord account, and select the desired channel. 5. In the “File URL” field of the Discord action, use the following expression: steps.previous_step_name.data.file_url (replace previous_step_name with the name of the previous step). Now, when your Telegram bot receives a message containing media, it will forward the media to the specified Discord channel.