如何将python输出发送到电报频道而不是组和gmail电子邮件组 [英] How to send python output to telegram CHANNEL not to Group and gmail email group

查看:225
本文介绍了如何将python输出发送到电报频道而不是组和gmail电子邮件组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python程序,每隔一小时产生一次结果。结果可能是任何东西。该程序将在本地计算机或虚拟专用网络中运行。

Hi I have a program in python that generates results every one hour. The result can be of anything.This program will run in local machine or in the virtual private network.

我有两个要求
1.发送此生成的python结果自动发送给一个电报组[组名 ourworld](由我创建),无需用户干预。 (我的台式机电报客户端正在运行,或者web.telegram.org在同一系统中运行)

I have two requirements 1. Send this python generated result to one telegram group [Group name "ourworld"](created by me) automatically without user intervention . (I have desktop telegram client running or web.telegram.org running in the same system)


  1. 将此结果发送到gmail组电子邮件ID。

有哪些方法可以满足此要求。是否有任何有效的代码可以完成此工作。请共享信息和详细信息。

what are the methods available to achieve this requirement .Is there any working code available to do this job .Please share the info and details.

编辑:

我是面对:


1.使用BotFather创建一个Bot。
2.将此Bot添加到我的组中,这里出现错误,无法添加成员,因此在
组中将Bot添加为管理员。3.BOT的令牌已记录下来。
4.在此论坛中尝试获取ChatId
https: //web.telegram.org/#/im?p=g154513121 )有人说p = g之后的数字是chartid,在我的情况下,没有
数字显示为@testingname。 / p>

1.created a Bot using BotFather. 2.Adding this Bot to my Group ,Here i get an error could not add an member So added the Bot as admin in the group 3.Token of the BOT noted down. 4. Trying to get ChatId in this forum (https://web.telegram.org/#/im?p=g154513121) someone says number after p=g is the chartid ,In my case there is no number it shows @testingname like this.


  1. 使用此方法尝试获取聊天ID https://api.telegram.org/bot738909732:AAE-2l7xAAlYHBXprK_a_bex09g9DMZbbDI/getme成为此处聊天室(a>
    909案例为什么我们需要单独的
    来获取图表ID)
    在这里,这确实是回应!这里的聊天ID是我的 testingname的ID,没有为该组生成图表ID。
    6.现在打包URL以查看响应,我收到此错误。


https://api.telegram.org/bot738909732 :AAE-2l7xAAlYHBXprK_a_bex09g9DMZbbDI / sendMessage?chat_id = 738909732& text = testing

如果我在浏览器中运行此输出

the output if i run this in browser


{ ok:false, error_code:400, description:错误的请求:未找到聊天
} { ok:false, error_code:403, description:禁止:bot
无法向bot发送消息}

{"ok":false,"error_code":400,"description":"Bad Request: chat not found"} {"ok":false,"error_code":403,"description":"Forbidden: bot can't send messages to bots"}

如何解决此问题并使BOT工作。为什么我无法将BOT添加到说无法添加用户错误的组中?

How to resolve this issue and make the BOT working .why i am not able to add BOT to my group that says error "Cant Add user"

如何制作此电报

注意:使用BotFather BOT创建的

Note : Using BotFather BOT created

推荐答案

要在没有任何用户干预的情况下将消息发送到电报组,您需要电报bot。使用电报bot-father创建一个。请查看此链接。在创建漫游器时还请注意令牌。此方法仅适用于电报组.Telegram频道,这是另一种要遵循的方法,MarxBabu在下面的答复中对此进行了回答。

to send message to the telegram "group" without any user intervention , you require a telegram bot. create one using telegram bot-father. take a look at this link. also note the token while creating the bot. This method will work only for telegram Group .Telegram channel another method to be followed which MarxBabu answered below in his answers post.

import requests

# telegram url
url = "https://api.telegram.org/bot<Token>"

def send_mess(text):
    params = {'chat_id':-xxxxxxx, 'text': text}
    response = requests.post(url + 'sendMessage', data=params)
    return response


send_mess(result_you_want_to_send) 

要获取chat_id,请遵循此处所述的步骤。注意:群组聊天ID始终以-开头。例如组chat_id -356163873。令牌和chat_id只是向电报组发送消息所需的条件。

to get the chat_id follow the steps mentioned here. note: group chat id's always starts with '-' . e.g. of group chat_id -356163873. A token and chat_id is only what you require to send message to telegram group.

要发送组电子邮件,您必须搜索更多,因为我不太了解

for sending group emails you have to search more as i do not know much

这篇关于如何将python输出发送到电报频道而不是组和gmail电子邮件组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆