def telegram(self, msg):
"""
REQUIRED msg params:
chat_id: int, telegram user chat id
message: string, message to be sent
Optional:
Markdown: bool, if markdown should be parsed or not
disable_web_page_preview: bool, if preview should be sent or not
Changes
1) picture: path of picture to be sent
2) sticker: file id of sticker to be sent (sends message after sticker)
"""
# Connect to rabbitmq
parameters = pika.URLParameters('amqp://'+self.RMQUSER+':'+self.RMQPASS+'@'+self.RMQHOST+':'+self.RMQPORT+'/'+self.RMQVHOST+'?socket_timeout='+self.RMQSOCKETTIMEOUT)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='telegram')
if isinstance(msg, list):
for m in msg:
logger.info("Sending msg to telegram: "+str(m))
channel.basic_publish(exchange='',routing_key='telegram',body=json.dumps(m))
else:
logger.info("Sending msg to telegram: "+str(msg))
channel.basic_publish(exchange='',routing_key='telegram',body=json.dumps(msg))
connection.close()
#####################
# MAIN
#####################
__init__.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录