0.0.11 many chages, see changelog
This commit is contained in:
50
tgbot/api.py
50
tgbot/api.py
@@ -22,7 +22,7 @@ def delete_message(cid: str, mid: str):
|
||||
|
||||
# https://core.telegram.org/bots/api#sendmessage
|
||||
def send_message(cid: str, body, reply_to=None, reply_markup=None):
|
||||
url = apiBase + f"sendMessage?chat_id={cid}&text={body}"
|
||||
url = f"sendMessage?chat_id={cid}&text={body}"
|
||||
if reply_to:
|
||||
url += f'&reply_to_message_id={reply_to}'
|
||||
if reply_markup:
|
||||
@@ -30,12 +30,13 @@ def send_message(cid: str, body, reply_to=None, reply_markup=None):
|
||||
reply_markup = requests.utils.quote(reply_markup)
|
||||
url += f'&reply_markup={reply_markup}'
|
||||
url += f'&parse_mode=html'
|
||||
r = requests.post(url)
|
||||
print(url)
|
||||
r = requests.post(apiBase + url)
|
||||
return r.json()
|
||||
|
||||
# https://core.telegram.org/bots/api#sendphoto
|
||||
def send_photo(cid: str, file_id: str, caption="", reply_to=None, reply_markup=None):
|
||||
url = apiBase + f"sendPhoto?chat_id={cid}&photo={file_id}"
|
||||
url = f"sendPhoto?chat_id={cid}&photo={file_id}&caption={caption}"
|
||||
if reply_to:
|
||||
url += f'&reply_to_message_id={reply_to}'
|
||||
if reply_markup:
|
||||
@@ -43,7 +44,8 @@ def send_photo(cid: str, file_id: str, caption="", reply_to=None, reply_markup=N
|
||||
reply_markup = requests.utils.quote(reply_markup)
|
||||
url += f'&reply_markup={reply_markup}'
|
||||
url += f'&parse_mode=html'
|
||||
r = requests.post(url)
|
||||
print(url)
|
||||
r = requests.post(apiBase + url)
|
||||
return r.json()
|
||||
|
||||
|
||||
@@ -88,8 +90,21 @@ def mute_member(chat_id, member_id):
|
||||
|
||||
|
||||
# https://core.telegram.org/bots/api#restrictchatmember
|
||||
def unmute_member(chat_id, member_id):
|
||||
chat_permissions = json.dumps({ "can_send_messages": True })
|
||||
def unmute_member(chat_id, member_id, chat_permissions=None):
|
||||
if not chat_permissions:
|
||||
chat_permissions = json.dumps({
|
||||
"can_send_messages": True,
|
||||
"can_send_photos": True,
|
||||
"can_send_other_messages": True,
|
||||
"can_send_polls": True,
|
||||
"can_add_web_page_previews": True,
|
||||
"can_send_audios": True,
|
||||
"can_invite_users": True,
|
||||
"can_send_voice_notes": True,
|
||||
"can_send_video_notes": True,
|
||||
"can_send_videos": True,
|
||||
"can_send_documents": True
|
||||
})
|
||||
chat_permissions = requests.utils.quote(chat_permissions)
|
||||
url = apiBase + f'restrictChatMember?chat_id={chat_id}' + \
|
||||
f'&user_id={member_id}&permissions={chat_permissions}' + \
|
||||
@@ -145,4 +160,27 @@ def get_member(chat_id, member_id):
|
||||
def get_userphotos(user_id):
|
||||
url = apiBase + f"getUserProfilePhotos?user_id={user_id}"
|
||||
r = requests.get(url)
|
||||
return r.json()
|
||||
|
||||
# https://core.telegram.org/bots/api#editmessagereplymarkup
|
||||
def edit_replymarkup(cid, mid, reply_markup):
|
||||
url = apiBase + f"editMessageText?chat_id={cid}&message_id={mid}&reply_markup={text}"
|
||||
r = requests.post(url)
|
||||
return r.json()
|
||||
|
||||
|
||||
# https://core.telegram.org/bots/api#getchat
|
||||
def get_chat(cid):
|
||||
url = apiBase + f"getChat?chat_id={cid}"
|
||||
r = requests.get(url)
|
||||
return r.json()
|
||||
|
||||
|
||||
# https://core.telegram.org/bots/api#banchatmember
|
||||
def kick_member(chat_id, member_id):
|
||||
url = f"banChatSenderChat?chat_id={cid}&user_id={member_id}"
|
||||
r = requests.post(apiBase + url)
|
||||
print(r.json())
|
||||
url = f"unbanChatSenderChat?chat_id={cid}&user_id={member_id}&only_if_banned=1"
|
||||
r = requests.post(apiBase + url)
|
||||
return r.json()
|
Reference in New Issue
Block a user