mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2026-04-19 21:23:50 +00:00
neue Funktion msg_send und aufruf davon mit Payload in "onLoad" und "zvei"
This commit is contained in:
parent
194a7ef8aa
commit
11a456a1ef
1 changed files with 18 additions and 42 deletions
|
|
@ -35,26 +35,33 @@ class BoswatchPlugin(PluginBase):
|
||||||
"""!Do not change anything here!"""
|
"""!Do not change anything here!"""
|
||||||
super().__init__(__name__, config) # you can access the config class on 'self.config'
|
super().__init__(__name__, config) # you can access the config class on 'self.config'
|
||||||
|
|
||||||
def onLoad(self):
|
def msg_send(self, bwPacket, msg_payload):
|
||||||
"""!Called by import of the plugin"""
|
"""!Funktion zum Senden einer Nachricht über Telegram
|
||||||
bot_token = self.config.get("botToken") #Import von Token aus config/server.yaml
|
@param bwPacket: bwPacket instance
|
||||||
chat_id = self.config.get("chatIds") #Import von ChatIDs aus config/server.yaml
|
@param msg_payload: Nachrichtentext, der gesendet werden soll"""
|
||||||
msg_payload = "Server up and running!"
|
|
||||||
|
bot_token = self.config.get("botToken")
|
||||||
|
chat_id = self.config.get("chatIds")
|
||||||
|
|
||||||
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
|
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
|
||||||
payload = {
|
payload = {
|
||||||
'chat_id': chat_id,
|
'chat_id': chat_id,
|
||||||
'text': msg_payload
|
'text': msg_payload
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(url, data=payload)
|
response = requests.post(url, data=payload)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
print("Nachricht erfolgreich gesendet!")
|
print("Nachricht erfolgreich gesendet!")
|
||||||
else:
|
else:
|
||||||
print("Fehler beim Senden:", response.text)
|
print("Fehler beim Senden:", response.text)
|
||||||
|
|
||||||
|
def onLoad(self):
|
||||||
|
"""!Called by import of the plugin"""
|
||||||
|
msg_payload = "Server up and running!"
|
||||||
|
self.msg_send(None, msg_payload)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
"""!Called before alarm
|
"""!Called before alarm
|
||||||
Remove if not implemented"""
|
Remove if not implemented"""
|
||||||
|
|
@ -77,21 +84,10 @@ class BoswatchPlugin(PluginBase):
|
||||||
def zvei(self, bwPacket):
|
def zvei(self, bwPacket):
|
||||||
"""!Called on ZVEI alarm
|
"""!Called on ZVEI alarm
|
||||||
@param bwPacket: bwPacket instance"""
|
@param bwPacket: bwPacket instance"""
|
||||||
bot_token = self.config.get("botToken") #Import von Token aus config/server.yaml
|
msg_payload = self.parseWildcards(
|
||||||
chat_id = self.config.get("chatIds") #Import von ChatIDs aus config/server.yaml
|
self.config.get("message_zvei", default="{TONE}") # Übergabe mit Wildcards aus config/server.yaml der "message_zvei", falls nicht definiert, Defaultwert
|
||||||
msg_payload = self.parseWildcards(self.config.get("message_zvei", default="{TONE}")) # Übergabe mit Wildcards aus config/server.yaml der "message_zvei", falls nicht definiert, Defaultwert
|
)
|
||||||
#msg_payload = bwPacket.get("clientName") + ": " + (bwPacket.get("description") or bwPacket.get("tone")) # Name vom Client und ": " und wenn Description vorhanden, ansonsten ZVEI
|
self.msg_send(bwPacket, msg_payload)
|
||||||
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
|
|
||||||
payload = {
|
|
||||||
'chat_id': chat_id,
|
|
||||||
'text': msg_payload
|
|
||||||
}
|
|
||||||
response = requests.post(url, data=payload)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
print("Nachricht erfolgreich gesendet!")
|
|
||||||
else:
|
|
||||||
print("Fehler beim Senden:", response.text)
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def msg(self, bwPacket):
|
def msg(self, bwPacket):
|
||||||
|
|
@ -110,23 +106,3 @@ class BoswatchPlugin(PluginBase):
|
||||||
"""!Called by destruction of the plugin
|
"""!Called by destruction of the plugin
|
||||||
Remove if not implemented"""
|
Remove if not implemented"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def msg_send(self, bwPacket):
|
|
||||||
"""!Funktion zum senden einer Nachricht
|
|
||||||
@param bwPacket: bwPacket instance"""
|
|
||||||
bot_token = self.config.get("botToken") #Import von Token aus config/server.yaml
|
|
||||||
chat_id = self.config.get("chatIds") #Import von ChatIDs aus config/server.yaml
|
|
||||||
msg_payload = self.parseWildcards(self.config.get("message_zvei", default="{TONE}")) # Übergabe mit Wildcards aus config/server.yaml der "message_zvei", falls nicht definiert, Defaultwert
|
|
||||||
#msg_payload = bwPacket.get("clientName") + ": " + (bwPacket.get("description") or bwPacket.get("tone")) # mit bwPacket anstelle Wildcards: Name vom Client und ": " und wenn Description vorhanden, ansonsten ZVEI
|
|
||||||
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
|
|
||||||
payload = {
|
|
||||||
'chat_id': chat_id,
|
|
||||||
'text': msg_payload
|
|
||||||
}
|
|
||||||
response = requests.post(url, data=payload)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
print("Nachricht erfolgreich gesendet!")
|
|
||||||
else:
|
|
||||||
print("Fehler beim Senden:", response.text)
|
|
||||||
pass
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue