-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
46 lines (31 loc) · 1.34 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import telegram
from config import *
if not TELEGRAM_KEY:
import os
TELEGRAM_KEY = os.environ.get('TELEGRAM_KEY', None)
# GET AUTH FOR USE TELEGRAM API
bot = telegram.Bot(token=TELEGRAM_KEY)
chat_id = "@inumet_alertas"
# SEND PHOTO
# status = bot.sendPhoto(chat_id="@inumet_alertas", photo="https://images.unsplash.com/photo-1568216874968-b74b3b69872b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=683&q=80", parse_mode=telegram.ParseMode.HTML, caption = "Alerta naranja")
def sendMessage(message):
# Send message to channel
status = bot.send_message(chat_id=chat_id, text=message, parse_mode=telegram.ParseMode.HTML)
return status
def sendPhoto(url_photo, caption):
# Send photo to channel
status = bot.sendPhoto(chat_id=chat_id, photo=url_photo, caption = caption, parse_mode=telegram.ParseMode.HTML)
return status
def sendMediaGroup(media, caption):
media_to_send = []
# Append the first element with captions
media_to_send.append(telegram.InputMediaPhoto(media[0], caption=caption, parse_mode=None))
# And remove from media
media.pop(0)
# For the other -> Append to array
for element in media:
media_to_send.append(telegram.InputMediaPhoto(element))
status = bot.sendMediaGroup(chat_id=chat_id, media=media_to_send)
return status
# status_multiple = sendMediaGroup()
# print(status_multiple)