Compare commits
	
		
			No commits in common. "6bedd576bee495dd4da3f19dff91f464b0f59915" and "040bd085039f8fb73da2c3afbc130e270d21e5d0" have entirely different histories.
		
	
	
		
			6bedd576be
			...
			040bd08503
		
	
		
@ -1,71 +0,0 @@
 | 
				
			|||||||
#!/bin/env python3
 | 
					 | 
				
			||||||
import websocket
 | 
					 | 
				
			||||||
import json
 | 
					 | 
				
			||||||
import random
 | 
					 | 
				
			||||||
import zmq
 | 
					 | 
				
			||||||
from pprint import pprint
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
__version__ = "2.0.0b2"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ws = None
 | 
					 | 
				
			||||||
uri = "ws://localhost:5080"
 | 
					 | 
				
			||||||
ws = websocket.create_connection(uri)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
context = zmq.Context()
 | 
					 | 
				
			||||||
socket = context.socket(zmq.REP)
 | 
					 | 
				
			||||||
socket.bind("tcp://*:5555")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def sendsmpmessage(target, message):
 | 
					 | 
				
			||||||
    global ws
 | 
					 | 
				
			||||||
    print("Sendmessage %s called to %s" % (message, target))
 | 
					 | 
				
			||||||
    msg = ("%s %s" % (target, message))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Create a unique correlation ID
 | 
					 | 
				
			||||||
    command = {
 | 
					 | 
				
			||||||
        "corrId": f"id{random.randint(0, 999999)}",
 | 
					 | 
				
			||||||
        "cmd": msg,
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    json_command = json.dumps(command)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    """ Connects to WebSocket server, sends a message, and returns the response """
 | 
					 | 
				
			||||||
    if ws is None:
 | 
					 | 
				
			||||||
        uri = "ws://localhost:5080"
 | 
					 | 
				
			||||||
        ws = websocket.create_connection(uri)  # Blocking WebSocket connection
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ws.send(json_command)  # Send message to WebSocket
 | 
					 | 
				
			||||||
    responsejson = ws.recv()  # Receive response
 | 
					 | 
				
			||||||
    response = json.loads(responsejson)
 | 
					 | 
				
			||||||
    # ws.close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for chatitem in response['resp']['chatItems']:
 | 
					 | 
				
			||||||
        statusdict = chatitem['chatItem']['meta']['itemStatus']
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            status = statusdict['sndProgress']
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            print("FAILED")
 | 
					 | 
				
			||||||
            status = 'FAILED'
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            smessage = chatitem['chatItem']['meta']['itemText']
 | 
					 | 
				
			||||||
            print("Message '%s' sent over websocket to %s, status was %s" % (smessage, target, status))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if status == 'complete':
 | 
					 | 
				
			||||||
            return True
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            return False
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == '__main__':
 | 
					 | 
				
			||||||
    while True:
 | 
					 | 
				
			||||||
        zmq = socket.recv_string()
 | 
					 | 
				
			||||||
        print(f"Received request: {zmqmessage}")
 | 
					 | 
				
			||||||
        result = True
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        decoded = json.loads(zmqmessage)
 | 
					 | 
				
			||||||
        pprint(decoded)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        result = sendmessage(decoded.get('target'), decoded.get('message'))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if result is True:
 | 
					 | 
				
			||||||
            socket.send_string("sent")
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            socket.send_string("failed")
 | 
					 | 
				
			||||||
@ -4,33 +4,57 @@ import websocket
 | 
				
			|||||||
import json
 | 
					import json
 | 
				
			||||||
import yaml
 | 
					import yaml
 | 
				
			||||||
import random
 | 
					import random
 | 
				
			||||||
 | 
					import threading
 | 
				
			||||||
from pprint import pprint
 | 
					from pprint import pprint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__version__ = "2.0.0b2"
 | 
					__version__ = "2.0.0b2"
 | 
				
			||||||
versionstring='Taurix TellMe server v' + __version__
 | 
					versionstring='Taurix TellMe server v' + __version__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app = Flask(__name__)
 | 
					app = Flask(__name__)
 | 
				
			||||||
 | 
					lock = threading.Lock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
socket = context.socket(zmq.REQ)
 | 
					ws = None
 | 
				
			||||||
socket.connect("tcp://localhost:5555")
 | 
					uri = "ws://localhost:5080"
 | 
				
			||||||
 | 
					ws = websocket.create_connection(uri)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hooks = {}
 | 
					hooks = {}
 | 
				
			||||||
with open(r'/etc/tellme/hooks.yml') as hooksfile:
 | 
					with open(r'/etc/tellme/hooks.yml') as hooksfile:
 | 
				
			||||||
    hooks = yaml.load(hooksfile, Loader=yaml.FullLoader)
 | 
					    hooks = yaml.load(hooksfile, Loader=yaml.FullLoader)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
def sendmessage(target, message):
 | 
					def sendmessage(target, message):
 | 
				
			||||||
    global socket
 | 
					    global ws
 | 
				
			||||||
    jsonmessage = {}
 | 
					    print("Sendmessage %s called to %s" % (message, target))
 | 
				
			||||||
    jsonmessage['target'] = target
 | 
					    msg = ("%s %s" % (target, message))
 | 
				
			||||||
    jsonmessage['message'] = message
 | 
					 | 
				
			||||||
    socket.send_string(json.dumps(jsonmessage))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Wait for a reply
 | 
					    # Create a unique correlation ID
 | 
				
			||||||
    reply = socket.recv_string()
 | 
					    command = {
 | 
				
			||||||
    print(f"Received reply: {reply}")
 | 
					        "corrId": f"id{random.randint(0, 999999)}",
 | 
				
			||||||
 | 
					        "cmd": msg,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    json_command = json.dumps(command)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if reply == 'sent':
 | 
					    """ Connects to WebSocket server, sends a message, and returns the response """
 | 
				
			||||||
 | 
					    if ws is None:
 | 
				
			||||||
 | 
					        uri = "ws://localhost:5080"
 | 
				
			||||||
 | 
					        ws = websocket.create_connection(uri)  # Blocking WebSocket connection
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ws.send(json_command)  # Send message to WebSocket
 | 
				
			||||||
 | 
					    responsejson = ws.recv()  # Receive response
 | 
				
			||||||
 | 
					    response = json.loads(responsejson)
 | 
				
			||||||
 | 
					    # ws.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for chatitem in response['resp']['chatItems']:
 | 
				
			||||||
 | 
					        statusdict = chatitem['chatItem']['meta']['itemStatus']
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            status = statusdict['sndProgress']
 | 
				
			||||||
 | 
					        except KeyError:
 | 
				
			||||||
 | 
					            print("FAILED")
 | 
				
			||||||
 | 
					            status = 'FAILED'
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            smessage = chatitem['chatItem']['meta']['itemText']
 | 
				
			||||||
 | 
					            print("Message '%s' sent over websocket to %s, status was %s" % (smessage, target, status))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if status == 'complete':
 | 
				
			||||||
            return True
 | 
					            return True
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
 | 
				
			|||||||
@ -1,12 +0,0 @@
 | 
				
			|||||||
[Unit]
 | 
					 | 
				
			||||||
Description=Tellme Notifier
 | 
					 | 
				
			||||||
After=network.target
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[Service]
 | 
					 | 
				
			||||||
User=tellme
 | 
					 | 
				
			||||||
WorkingDirectory=/opt/tellme
 | 
					 | 
				
			||||||
ExecStart=notifier.py
 | 
					 | 
				
			||||||
Restart=always
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[Install]
 | 
					 | 
				
			||||||
WantedBy=multi-user.target
 | 
					 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user