Send report using telegram integration

Hi,

How can I send report in erpnext using telegram bot, within scheduled time

I would:

  • Create the report in the ERPNext.
  • Set it up in the “Auto email report”.
  • Sent the email to the n8n instance.
  • Sent the contents to the Telegram via n8n.

It may seem a long road but it’s relatively easy.

PS: There is an community app which adds Telegram option in the Notification settings. I can’t remember if it also supports email reporting.

Thank you for your reply @TurkerTunali, but I need to send it in specific time that mean I need to use corn job and this not supported in auto email report,

If there is way to send it direct to telegram bot will be better

am trying with below code but it’s not work
error_message: Error: ‘str’ object has no attribute ‘update’

import requests
import frappe
from frappe.utils.pdf import get_pdf

# Function to send a document from ERPNext via Telegram
def send_document_via_telegram(invoice_name, chat_id, bot_token):
    try:
        # Get the Sales Invoice document
        invoice = frappe.get_doc("Sales Invoice", invoice_name)
        
        # Generate the PDF for the Sales Invoice
        pdf_data = get_pdf("Sales Invoice", invoice_name)
        
        # Prepare the data for the Telegram API
        data = {
            "chat_id": chat_id,
            "document": ("invoice.pdf", pdf_data, "application/pdf"),
            "caption": f"Sales Invoice: {invoice.name}"
        }
        
        # Send the document via Telegram Bot API
        telegram_api_url = f"https://api.telegram.org/bot{bot_token}/sendDocument"
        response = requests.post(telegram_api_url, files=data)
        
        if response.status_code == 200:
            print("Document sent successfully via Telegram!")
        else:
            print("Error sending document via Telegram:", response.text)
    except Exception as e:
        print("Error:", str(e))

n8n have a wait node. At night n8n can get the email but you may send the telegram message at a specific time.