2016-02-16 61 views
1

我正在做一個在Raspberry Pi上使用Telegram的項目。目前,我正在使用XBEE在按下按鈕時讀取高輸入。目前,我可以在按下按鈕時發送短信。我打算在我的代碼中實現電報,以便它將同時發送SMS和電報消息。我還在RPI上安裝了Telegram API。如何包含代碼來啓動電報服務器併發送消息。按下按鈕時從Raspberry Pi發送報文

我的代碼如下所示,

if stat1.strip() in "Enable enable ENABLE": 

      try: 
        recipient= () 
        for item in numbers: 
          recipient= item[0] 
          print recipient 
          gsm.send_sms(recipient, 'Panic activated!') 
          sendSmsNow = True 
          print "panic message sent" 
          time.sleep(5) 

      except Exception as e: 
        print e 

回答

0

可以使用python-telegram-bot從Python的將消息發送到電報。該項目的示例文件夾中有一些示例。

它的要點:

from telegram import Updater 
import logging 

# Enable logging 
logging.basicConfig(
     format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 
     level=logging.INFO) 

logger = logging.getLogger(__name__) 


# Define a few command handlers. These usually take the two arguments bot and 
# update. Error handlers also receive the raised TelegramError object in error. 
def start(bot, update): 
    bot.sendMessage(update.message.chat_id, text='Hi!') 

退房代碼here