如何将 Telethon 与 Google 云功能一起使用
How to use Telethon with Google Cloud Functions
我是 python 的新手,我想用 Telethon 设置一个 google 云函数,但我做不到,因为我在 [=29= 时遇到错误]宁.
这是Gcloud函数代码我的代码:
from telethon import TelegramClient, events, sync
#from telethon import functions, types
#from telethon.tl.functions.channels import CreateChannelRequest, CheckUsernameRequest, UpdateUsernameRequest, InviteToChannelRequest
#from telethon.tl.types import InputChannel, InputPeerChannel
api_id = XXX
api_hash = 'XXX'
def hello_world(request):
with TelegramClient("session_name", api_id, api_hash) as client:
from telethon.tl.functions.channels import CreateChannelRequest, CheckUsernameRequest, UpdateUsernameRequest
from telethon.tl.types import InputChannel, InputPeerChannel
from telethon.tl.types import InputPhoneContact
from telethon.tl.types import InputPeerUser
from telethon.tl.functions.contacts import ImportContactsRequest
contact = InputPhoneContact(client_id=11111, phone='1111111111', first_name="Twilo Test",last_name="Phone")
newcontact = client(ImportContactsRequest(contacts=[contact]))
return newcontact.__dict__;
我的requeriments.txt:
# Function dependencies, for example:
# package>=version
telethon
当我 运行 函数 (hello_world):
时出现以下错误
您的数据库的名称和位置是 session_name
。
在 Google 上,只有云函数 /tmp
是可写的。
它必须看起来像这样:
with TelegramClient("/tmp/session_name", api_id, api_hash) as client:
我是 python 的新手,我想用 Telethon 设置一个 google 云函数,但我做不到,因为我在 [=29= 时遇到错误]宁.
这是Gcloud函数代码我的代码:
from telethon import TelegramClient, events, sync
#from telethon import functions, types
#from telethon.tl.functions.channels import CreateChannelRequest, CheckUsernameRequest, UpdateUsernameRequest, InviteToChannelRequest
#from telethon.tl.types import InputChannel, InputPeerChannel
api_id = XXX
api_hash = 'XXX'
def hello_world(request):
with TelegramClient("session_name", api_id, api_hash) as client:
from telethon.tl.functions.channels import CreateChannelRequest, CheckUsernameRequest, UpdateUsernameRequest
from telethon.tl.types import InputChannel, InputPeerChannel
from telethon.tl.types import InputPhoneContact
from telethon.tl.types import InputPeerUser
from telethon.tl.functions.contacts import ImportContactsRequest
contact = InputPhoneContact(client_id=11111, phone='1111111111', first_name="Twilo Test",last_name="Phone")
newcontact = client(ImportContactsRequest(contacts=[contact]))
return newcontact.__dict__;
我的requeriments.txt:
# Function dependencies, for example:
# package>=version
telethon
当我 运行 函数 (hello_world):
时出现以下错误您的数据库的名称和位置是 session_name
。
在 Google 上,只有云函数 /tmp
是可写的。
它必须看起来像这样:
with TelegramClient("/tmp/session_name", api_id, api_hash) as client: