Generate pdf and send using telegram

Hi,

The below code sends messages to the telegram bot successfully, but I need to send the document as Pdf not a message,

def send_text_via_telegram():
    try:
        chat_id = #######
        bot_token = "#################################"
        # Get Daily Report Workers details
        text = ""
        daily_report = frappe.db.sql("""
            SELECT
                dr.name,
                dr.customer_agreement as "اتفاقية الزبون",
                dr.supervisor as "سوبرفايزر",
                dr.posting_date as "تاريخ",
                prw.plan_as_worker as "خطة يوم غد",
                prw.login_time as "عدد الخطة",
                drw.actual_worker as "الواقع",
                drw.number as "عدد الواقع",
                drw.actual_login_time as "وقت الحضور",
                drw.logout_time as "وقت الخروج",
                drw.note as "ملاحظات"
            FROM
                `tabDaily Report Workers` dr
            LEFT JOIN
                `tabDaily Report Workers Actual Item` drw on drw.parent = dr.name
            LEFT JOIN
                `tabDaily Report Workers Plan Item` prw on prw.parent = dr.name
            WHERE
                dr.posting_date = %s
            GROUP BY 
                prw.plan_as_worker, drw.actual_worker
        """, frappe.utils.today() ,as_dict=True)
        if daily_report:
            for row in daily_report:
                text += f"Name: {row.get('name')}\n"
                text += f"اتفاقية الزبون: {row.get('اتفاقية الزبون')}\n"
                text += f"سوبرفايزر: {row.get('سوبرفايزر')}\n"
                text += f"تاريخ: {row.get('تاريخ')}\n"
                text += f"خطة يوم غد: {row.get('خطة يوم غد')}\n"
                text += f"عدد الخطة: {row.get('عدد الخطة')}\n"
                text += f"الواقع: {row.get('الواقع')}\n"
                text += f"عدد الواقع: {row.get('عدد الواقع')}\n"
                text += f"وقت الحضور: {row.get('وقت الحضور')}\n"
                text += f"وقت الخروج: {row.get('وقت الخروج')}\n"
                text += f"ملاحظات: {row.get('ملاحظات')}\n"
                text += "\n"
        else:
            text += "No Daily Report Workers found.\n"

        # Prepare the data for the Telegram API
        data = {
            "chat_id": chat_id,
            "text": text
        }
        
        # Send the text message via Telegram Bot API
        telegram_api_url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
        response = requests.post(telegram_api_url, data=data)
        
        if response.status_code == 200:
            print("Text message sent successfully via Telegram!")
        else:
            print("Error sending text message via Telegram:", response.text)
    except Exception as e:
        print("Error:", str(e))```
1 Like

I solved

can you share a solution here ? , i am trying with whatsapp & telegram