Moved notifier into main process

This commit is contained in:
2026-04-22 14:27:36 +02:00
parent 9e1e072620
commit 3e8fb97881
3 changed files with 26 additions and 26 deletions

View File

@@ -3,17 +3,17 @@ from flask import Flask, request, jsonify
import websocket
import json
import yaml
import zmq
import random
from pprint import pprint
__version__ = "2.1.1"
__version__ = "2.2.0"
versionstring='Taurix TellMe server v' + __version__
app = Flask(__name__)
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")
# context = zmq.Context()
# socket = context.socket(zmq.REQ)
# socket.connect("tcp://localhost:5555")
hooks = {}
with open(r'/etc/tellme/hooks.yml') as hooksfile:
@@ -21,17 +21,26 @@ with open(r'/etc/tellme/hooks.yml') as hooksfile:
def sendmessage(target, message):
global socket
jsonmessage = {}
jsonmessage['target'] = target
jsonmessage['message'] = message
socket.send_string(json.dumps(jsonmessage))
# global socket
# Wait for a reply
reply = socket.recv_string()
print(f"Received reply: {reply}")
msg = ("%s %s" % (target, message))
if reply == 'sent':
# Create a unique correlation ID
command = {
"corrId": f"id{random.randint(0, 999999)}",
"cmd": msg,
}
json_command = json.dumps(command)
uri = "ws://localhost:5080"
ws = websocket.create_connection(uri)
ws.send(json_command) # Send message to WebSocket
responsejson = ws.recv() # Receive response
response = json.loads(responsejson)
ws.close()
if response is not None:
return True
else:
return False