텔레그램 메시지 인터페이스 V2.0.0 파이썬

저자:포크스팬, 날짜: 2018-09-12 02:29:33
태그:푸시메시지

Telegram API 인터페이스FMZ.com)

이 라이브러리는 현재 Telegram에만 사용할 수 있습니다. 더 많은 기능이 추가될 예정입니다.

초기화

# key 为 Bot key
## 获取 Bot key 可以参考 https://www.ccino.org/create-a-telegram-bot.html
# chat_id 为收信用户Telegram ID
## Telegram ID 可以通过 @dwx_aibot 机器人获取, 连接至此机器人后发送 /getid 即可获得 ChatID
Telegram = ext.Telegram(key=string, chat_id=integer)    # 创建一个新的接口对象

메세지

# chat_id 为可选项 默认会使用初始化时设置的ChatID
# message 即为信息内容
Telegram.Send(message=string, chat_id=integer)

주의사항

Telegram에서 자신의 로봇에 /start 메시지를 보내기 전에 스스로에게 메시지를 보낼 수 있습니다. 그렇지 않으면 로봇은 당신에게 메시지를 보낼 수 없습니다.

저를 연락하세요

우편함i@fawkex.me전신포크스팬

전략의 맞춤화

이 도서관에 대해

Telegram API 문서

WTFPL를 이용한 Do What the Fuck You Want to Public 라이선스


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# encoding: utf-8
# 
# Telegram Interface for FMZ.com
#
# Copyright 2018 FawkesPan
# Contact : i@fawkex.me / Telegram@FawkesPan
#
# Do What the Fuck You Want To Public License
#

try:
    import requests
except:
    print('Requests not installed. Try: pip install requests')
    Log('Requests not installed. Try: pip install requests')
    
    raise Exception('Requests not installed. Try: pip install requests')

class Telegram:
    def __init__(self):
        self.key = KEY
        self.chat_id = CHATID
        self.url = 'https://api.telegram.org/bot%s' % self.key
        
    def Send(self, message='', chat_id=None):
        if chat_id is None:
            chat_id = self.chat_id
        PARAM = {}
        PARAM['chat_id'] = chat_id
        PARAM['text'] = message
        PARAM['parse_mode'] = 'markdown'
        URL = self.url + '/sendMessage'
        try:
            res = requests.post(URL, data = PARAM)
            return True
        except IOError as e:
            print(e)
            return False
        

ext.Telegram = Telegram

# 模块功能测试
def main():
    if DEBUG == 1:
        msger = ext.Telegram(KEY, CHATID)
        msger.Send("Hello World!")
    
    return True

관련

더 많은

초목d 칭찬