From 4e1cf00cb38a2ef1ed3078953cac59e568110612 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Plogmann Date: Mon, 24 Apr 2017 20:08:37 +0200 Subject: [PATCH] read message-text from config --- config/config.template.ini | 39 +++++++++++++++++++++++++++++++++--- plugins/Telegram/Telegram.py | 16 +++++++++------ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index 2c74531..a8f141c 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -414,14 +414,47 @@ RICforLocationAPIKey = # This is your Google API key. # Required if you want to create a map based on location information received with the above RIC. GoogleAPIKey = + +# %FMS% = FMS Code +# %STATUS% = FMS Status +# %DIR% = Direction of the telegram (0/1) +# %DIRT% = Direction of the telegram (Text-String) +# %TSI% = Tactical Short Information (I-IV) +# %DESCR% = Description, if description-module is used +# %DATE% = Date (by script) +# %TIME% = Time (by script) +# %LPAR% = ( +# %RPAR% = ) +fms_message = %DATE% %TIME%: %FMS% + +# %ZVEI% = ZVEI 5-tone Code +# %DESCR% = Description, if description-module is used +# %DATE% = Date (by script) +# %TIME% = Time (by script) +# %LPAR% = ( +# %RPAR% = ) +zvei_message = %DATE% %TIME%: %ZVEI% + +# %RIC% = POCSAG RIC +# %FUNC% = POCSAG function/Subric (1-4) +# %FUNCCHAR% = POCSAG function/Subric als character (a-d) +# %MSG% = Message of the POCSAG telegram +# %BITRATE% = Bitrate of the POCSAG telegram +# %DESCR% = Description, if description-module is used +# %DATE% = Date (by script) +# %TIME% = Time (by script) +# %LPAR% = ( +# %RPAR% = ) +poc_message = %MSG% + [yowsup] # number or chat-number who whants to become the news -empfaenger = +empfaenger = # WhatsApp-number of that the news comes -sender = +sender = # password from this number -password= +password= # %FMS% = FMS Code # %STATUS% = FMS Status diff --git a/plugins/Telegram/Telegram.py b/plugins/Telegram/Telegram.py index 0d890c8..0b4c053 100644 --- a/plugins/Telegram/Telegram.py +++ b/plugins/Telegram/Telegram.py @@ -16,6 +16,7 @@ from telegram.error import (TelegramError, Unauthorized, BadRequest, NetworkErro from includes import globalVars # Global variables # Helper function, uncomment to use +from includes.helper import wildcardHandler from includes.helper import configHandler from includes.helper import timeHandler @@ -81,14 +82,15 @@ def run(typ,freq,data): if typ == "POC": logging.debug("Compose output from POCSAG-message") # compose message content - output = timeHandler.curtime()+"\n"+data["ric"]+"("+data["functionChar"]+")\n"+data["description"]+"\n"+data["msg"] + text = globalVars.config.get("Telegram","poc_message") + text = wildcardHandler.replaceWildcards(text, data) # Initiate Telegram Bot logging.debug("Initiate Telegram BOT") bot = telegram.Bot(token='%s' % BOTTokenAPIKey) # Send message to chat via Telegram BOT API logging.debug("Send message to chat via Telegram BOT API") - bot.sendMessage('%s' % BOTChatIDAPIKey, output) + bot.sendMessage('%s' % BOTChatIDAPIKey, "text") # Generate location information only for specific RIC if data["ric"] == RICforLocationAPIKey: @@ -116,25 +118,27 @@ def run(typ,freq,data): elif typ == "FMS": logging.debug("Compose output from FMS-message") # compose message content - output = timeHandler.curtime()+"\n"+data["fms"]+"\n"+data["description"]+"\n"+data["status"] + text = globalVars.config.get("Telegram","fms_message") + text = wildcardHandler.replaceWildcards(text, data) # Initiate Telegram Bot logging.debug("Initiate Telegram BOT") bot = telegram.Bot(token='%s' % BOTTokenAPIKey) # Send message to chat via Telegram BOT API logging.debug("Send message to chat via Telegram BOT API") - bot.sendMessage('%s' % BOTChatIDAPIKey, output) + bot.sendMessage('%s' % BOTChatIDAPIKey, "text") elif typ == "ZVEI": logging.debug("Compose output from ZVEI-message") # compose message content - output = timeHandler.curtime()+"\n"+data["zvei"]+"\n"+data["description"] + text = globalVars.config.get("Telegram","zvei_message") + text = wildcardHandler.replaceWildcards(text, data) # Initiate Telegram Bot logging.debug("Initiate Telegram BOT") bot = telegram.Bot(token='%s' % BOTTokenAPIKey) # Send message to chat via Telegram BOT API logging.debug("Send message to chat via Telegram BOT API") - bot.sendMessage('%s' % BOTChatIDAPIKey, output) + bot.sendMessage('%s' % BOTChatIDAPIKey, "text") else: logging.warning("Invalid Typ: %s", typ) except Unauthorized: