Compare commits
61 Commits
308f046d09
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b95b776418 | |||
| b6e11f148f | |||
| a9e4febaa5 | |||
| 25b17f93fc | |||
| e9f57dd3f9 | |||
| 845c937d80 | |||
| ecb2429a0d | |||
| 5509f5e177 | |||
| 73592dd53e | |||
| f92a44b5c1 | |||
| a969b950d1 | |||
| 6bedd576be | |||
| fbfc7d9992 | |||
| 040bd08503 | |||
| 90d50084a7 | |||
| 7af2455cb6 | |||
| fd0e386792 | |||
| 0595649afe | |||
| 7532b2a064 | |||
| 8fa91e5e5f | |||
| e364c7d965 | |||
| 62e7468eb2 | |||
| 50a721267a | |||
| 84394cb3b8 | |||
| 3bba7a51f3 | |||
| 5ee659c376 | |||
| e3b6d650b8 | |||
| 1b68889ac5 | |||
| 6529e1b88b | |||
| a529e1eb53 | |||
| a3010018d4 | |||
| 50ef25c129 | |||
| ee6bb28f6a | |||
| 3847d2ea96 | |||
| 958b51ba40 | |||
| 2302e9b166 | |||
| 068af17935 | |||
| e28d653921 | |||
| 2e9520d3cd | |||
| 150c03b05a | |||
| 761536274b | |||
| 26b6b4cd98 | |||
| f3ef9e55d5 | |||
| 06744aa5c7 | |||
| 38d9e87393 | |||
| 48791ee1f1 | |||
| 4801b74405 | |||
| 139a7fc7d3 | |||
| 125f5ca205 | |||
| 0229d5ee41 | |||
| 4d5d2b96bc | |||
| 79bdc2c65d | |||
| 0d9a37cf4e | |||
| 697483f240 | |||
| 0c4b224605 | |||
| 447361ace7 | |||
| d577758fce | |||
| 3a4842a4ec | |||
| 9f4c19fa5f | |||
| 522c5d243f | |||
| 06f93bb894 |
3
Ansible/tellme_notification/defaults/main.yml
Normal file
3
Ansible/tellme_notification/defaults/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
tellme_url: https://
|
||||
tellme_webhook: 123
|
||||
11
Ansible/tellme_notification/tasks/main.yml
Normal file
11
Ansible/tellme_notification/tasks/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: Send a tellme notification
|
||||
uri:
|
||||
url: "{{ tellme_url }}/webhook/{{ tellme_webhook }}"
|
||||
method: POST
|
||||
body:
|
||||
message: "EPS Ansible run completed"
|
||||
body_format: json
|
||||
delegate_to: mon01
|
||||
run_once: true
|
||||
ignore_errors: yes
|
||||
@@ -1,5 +1,5 @@
|
||||
TellMe (1.3.0)
|
||||
* Add support for mentions (-n)
|
||||
TellMe Server (2.0.0b2)
|
||||
* Add logging
|
||||
|
||||
TellMe (1.2.0)
|
||||
* Feature complete version
|
||||
TellMe Server (2.0.0b1)
|
||||
* First standalone bot with SimpleX support
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "TellMe",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.0b1",
|
||||
"description": "TellMe CLI",
|
||||
"scripts": {
|
||||
"dev": "webpack-dev-server --inline --hot"
|
||||
|
||||
@@ -39,8 +39,8 @@ def sendmessage(message):
|
||||
ran = True
|
||||
|
||||
|
||||
__version__ = "2.0.0"
|
||||
versionstring='TellMe v' + __version__
|
||||
__version__ = "2.0.0b1"
|
||||
versionstring='Taurix TellMe v' + __version__
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
|
||||
302
package-lock.json
generated
302
package-lock.json
generated
@@ -1,302 +0,0 @@
|
||||
{
|
||||
"name": "TellMe",
|
||||
"version": "1.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"abbrev": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
|
||||
},
|
||||
"argparse": {
|
||||
"version": "0.1.16",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-0.1.16.tgz",
|
||||
"integrity": "sha1-z9AeD7uj1srtBJ+9dY1A9lGW9Xw=",
|
||||
"requires": {
|
||||
"underscore": "~1.7.0",
|
||||
"underscore.string": "~2.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"underscore.string": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.4.0.tgz",
|
||||
"integrity": "sha1-jN2PusTi0uoefi6Al8QvRCKA+Fs="
|
||||
}
|
||||
}
|
||||
},
|
||||
"async": {
|
||||
"version": "0.1.22",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-0.1.22.tgz",
|
||||
"integrity": "sha1-D8GqoIig4+8Ovi2IMbqw3PiEUGE="
|
||||
},
|
||||
"coffee-script": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.3.3.tgz",
|
||||
"integrity": "sha1-FQ1rTLUiiUNp7+1qIQHCC8f0pPQ="
|
||||
},
|
||||
"colors": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-0.6.2.tgz",
|
||||
"integrity": "sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w="
|
||||
},
|
||||
"dateformat": {
|
||||
"version": "1.0.2-1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.2-1.2.3.tgz",
|
||||
"integrity": "sha1-sCIMAt6YYXQztyhRz0fePfLNvuk="
|
||||
},
|
||||
"esprima": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz",
|
||||
"integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0="
|
||||
},
|
||||
"eventemitter2": {
|
||||
"version": "0.4.14",
|
||||
"resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-0.4.14.tgz",
|
||||
"integrity": "sha1-j2G3XN4BKy6esoTUVFWDtWQ7Yas="
|
||||
},
|
||||
"exit": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz",
|
||||
"integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw="
|
||||
},
|
||||
"findup-sync": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.1.3.tgz",
|
||||
"integrity": "sha1-fz56l7gjksZTvwZYm9hRkOk8NoM=",
|
||||
"requires": {
|
||||
"glob": "~3.2.9",
|
||||
"lodash": "~2.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"glob": {
|
||||
"version": "3.2.11",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz",
|
||||
"integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=",
|
||||
"requires": {
|
||||
"inherits": "2",
|
||||
"minimatch": "0.3"
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz",
|
||||
"integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4="
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz",
|
||||
"integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=",
|
||||
"requires": {
|
||||
"lru-cache": "2",
|
||||
"sigmund": "~1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"getobject": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/getobject/-/getobject-0.1.0.tgz",
|
||||
"integrity": "sha1-BHpEl4n6Fg0Bj1SG7ZEyC27HiFw="
|
||||
},
|
||||
"glob": {
|
||||
"version": "3.1.21",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-3.1.21.tgz",
|
||||
"integrity": "sha1-0p4KBV3qUTj00H7UDomC6DwgZs0=",
|
||||
"requires": {
|
||||
"graceful-fs": "~1.2.0",
|
||||
"inherits": "1",
|
||||
"minimatch": "~0.2.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"inherits": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-1.0.2.tgz",
|
||||
"integrity": "sha1-ykMJ2t7mtUzAuNJH6NfHoJdb3Js="
|
||||
}
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.2.3.tgz",
|
||||
"integrity": "sha1-FaSAaldUfLLS2/J/QuiajDRRs2Q="
|
||||
},
|
||||
"grunt": {
|
||||
"version": "0.4.5",
|
||||
"resolved": "https://registry.npmjs.org/grunt/-/grunt-0.4.5.tgz",
|
||||
"integrity": "sha1-VpN81RlDJK3/bSB2MYMqnWuk5/A=",
|
||||
"requires": {
|
||||
"async": "~0.1.22",
|
||||
"coffee-script": "~1.3.3",
|
||||
"colors": "~0.6.2",
|
||||
"dateformat": "1.0.2-1.2.3",
|
||||
"eventemitter2": "~0.4.13",
|
||||
"exit": "~0.1.1",
|
||||
"findup-sync": "~0.1.2",
|
||||
"getobject": "~0.1.0",
|
||||
"glob": "~3.1.21",
|
||||
"grunt-legacy-log": "~0.1.0",
|
||||
"grunt-legacy-util": "~0.2.0",
|
||||
"hooker": "~0.2.3",
|
||||
"iconv-lite": "~0.2.11",
|
||||
"js-yaml": "~2.0.5",
|
||||
"lodash": "~0.9.2",
|
||||
"minimatch": "~0.2.12",
|
||||
"nopt": "~1.0.10",
|
||||
"rimraf": "~2.2.8",
|
||||
"underscore.string": "~2.2.1",
|
||||
"which": "~1.0.5"
|
||||
}
|
||||
},
|
||||
"grunt-legacy-log": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/grunt-legacy-log/-/grunt-legacy-log-0.1.3.tgz",
|
||||
"integrity": "sha1-7ClCboAwIa9ZAp+H0vnNczWgVTE=",
|
||||
"requires": {
|
||||
"colors": "~0.6.2",
|
||||
"grunt-legacy-log-utils": "~0.1.1",
|
||||
"hooker": "~0.2.3",
|
||||
"lodash": "~2.4.1",
|
||||
"underscore.string": "~2.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz",
|
||||
"integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4="
|
||||
},
|
||||
"underscore.string": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.3.3.tgz",
|
||||
"integrity": "sha1-ccCL9rQosRM/N+ePo6Icgvcymw0="
|
||||
}
|
||||
}
|
||||
},
|
||||
"grunt-legacy-log-utils": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/grunt-legacy-log-utils/-/grunt-legacy-log-utils-0.1.1.tgz",
|
||||
"integrity": "sha1-wHBrndkGThFvNvI/5OawSGcsD34=",
|
||||
"requires": {
|
||||
"colors": "~0.6.2",
|
||||
"lodash": "~2.4.1",
|
||||
"underscore.string": "~2.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz",
|
||||
"integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4="
|
||||
},
|
||||
"underscore.string": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.3.3.tgz",
|
||||
"integrity": "sha1-ccCL9rQosRM/N+ePo6Icgvcymw0="
|
||||
}
|
||||
}
|
||||
},
|
||||
"grunt-legacy-util": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/grunt-legacy-util/-/grunt-legacy-util-0.2.0.tgz",
|
||||
"integrity": "sha1-kzJIhNv343qf98Am3/RR2UqeVUs=",
|
||||
"requires": {
|
||||
"async": "~0.1.22",
|
||||
"exit": "~0.1.1",
|
||||
"getobject": "~0.1.0",
|
||||
"hooker": "~0.2.3",
|
||||
"lodash": "~0.9.2",
|
||||
"underscore.string": "~2.2.1",
|
||||
"which": "~1.0.5"
|
||||
}
|
||||
},
|
||||
"grunt-version": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/grunt-version/-/grunt-version-1.1.1.tgz",
|
||||
"integrity": "sha1-C58oAhLKPITKhEGmiK0aB6R05vM=",
|
||||
"requires": {
|
||||
"grunt": "0.4.5 - 1",
|
||||
"semver": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"hooker": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz",
|
||||
"integrity": "sha1-uDT3I8xKJCqmWWNFnfbZhMXT2Vk="
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.2.11",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.2.11.tgz",
|
||||
"integrity": "sha1-HOYKOleGSiktEyH/RgnKS7llrcg="
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"js-yaml": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-2.0.5.tgz",
|
||||
"integrity": "sha1-olrmUJmZ6X3yeMZxnaEb0Gh3Q6g=",
|
||||
"requires": {
|
||||
"argparse": "~ 0.1.11",
|
||||
"esprima": "~ 1.0.2"
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "0.9.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-0.9.2.tgz",
|
||||
"integrity": "sha1-jzSZxSRdNG1oLlsNO0B2fgnxqSw="
|
||||
},
|
||||
"lru-cache": {
|
||||
"version": "2.7.3",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz",
|
||||
"integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI="
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "0.2.14",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz",
|
||||
"integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=",
|
||||
"requires": {
|
||||
"lru-cache": "2",
|
||||
"sigmund": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"nopt": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz",
|
||||
"integrity": "sha1-bd0hvSoxQXuScn3Vhfim83YI6+4=",
|
||||
"requires": {
|
||||
"abbrev": "1"
|
||||
}
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "2.2.8",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz",
|
||||
"integrity": "sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI="
|
||||
},
|
||||
"semver": {
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz",
|
||||
"integrity": "sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto="
|
||||
},
|
||||
"sigmund": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
|
||||
"integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA="
|
||||
},
|
||||
"underscore": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz",
|
||||
"integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk="
|
||||
},
|
||||
"underscore.string": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.2.1.tgz",
|
||||
"integrity": "sha1-18D6KvXVoaZ/QlPa7pgTLnM/Dxk="
|
||||
},
|
||||
"which": {
|
||||
"version": "1.0.9",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-1.0.9.tgz",
|
||||
"integrity": "sha1-RgwdoPgQED0DIam2M6+eV15kSG8="
|
||||
}
|
||||
}
|
||||
}
|
||||
5
server/Changelog
Normal file
5
server/Changelog
Normal file
@@ -0,0 +1,5 @@
|
||||
TellMe (1.3.0)
|
||||
* Add support for mentions (-n)
|
||||
|
||||
TellMe (1.2.0)
|
||||
* Feature complete version
|
||||
14
server/package.json
Normal file
14
server/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "TellMe Server",
|
||||
"version": "2.0.0b2",
|
||||
"description": "TellMe Server",
|
||||
"scripts": {
|
||||
"dev": "webpack-dev-server --inline --hot"
|
||||
},
|
||||
"author": "Guy Van Sanden <guy@taurix.net>",
|
||||
"license": "AGPL",
|
||||
"dependencies": {
|
||||
"grunt": "~0.4.5",
|
||||
"grunt-version": "~1.1.0"
|
||||
}
|
||||
}
|
||||
11
server/simplex-bot.service
Normal file
11
server/simplex-bot.service
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Simplex TellMe Bot
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=tbot
|
||||
ExecStart=/usr/local/bin/simplex-chat -p 5080
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
80
server/src/notifier.py
Normal file
80
server/src/notifier.py
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/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()
|
||||
if response is not None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
# for chatitem in response['resp']['chatItems']:
|
||||
# statusdict = chatitem['chatItem']['meta']['itemStatus']
|
||||
# try:
|
||||
# status = statusdict['sndProgress']
|
||||
# except KeyError:
|
||||
# pprint(response['resp']['chatItems'])
|
||||
# print('---')
|
||||
# pprint(chatitem)
|
||||
# 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' or status == 'partial':
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Tellme Notifier started...")
|
||||
while True:
|
||||
zmqmessage = socket.recv_string()
|
||||
print(f"Received request: {zmqmessage}")
|
||||
result = True
|
||||
|
||||
decoded = json.loads(zmqmessage)
|
||||
pprint(decoded)
|
||||
|
||||
result = sendsmpmessage(decoded.get('target'), decoded.get('message'))
|
||||
print(result)
|
||||
|
||||
if result is True:
|
||||
socket.send_string("sent")
|
||||
else:
|
||||
socket.send_string("failed")
|
||||
@@ -3,52 +3,65 @@ from flask import Flask, request, jsonify
|
||||
import websocket
|
||||
import json
|
||||
import yaml
|
||||
import random
|
||||
import zmq
|
||||
from pprint import pprint
|
||||
|
||||
__version__ = "2.0.0"
|
||||
versionstring='TellMe server v' + __version__
|
||||
__version__ = "2.0.0b2"
|
||||
versionstring='Taurix TellMe server v' + __version__
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.REQ)
|
||||
socket.connect("tcp://localhost:5555")
|
||||
|
||||
hooks = {}
|
||||
with open(r'/etc/tellme/hooks.yml') as hooksfile:
|
||||
hooks = yaml.load(hooksfile, Loader=yaml.FullLoader)
|
||||
|
||||
|
||||
def sendmessage(target, message):
|
||||
print("Sendmessage %s called to %s" % (message, target))
|
||||
#message = "#Bottest Hello, world!"
|
||||
msg = ("%s %s" % (target, message))
|
||||
global socket
|
||||
jsonmessage = {}
|
||||
jsonmessage['target'] = target
|
||||
jsonmessage['message'] = message
|
||||
socket.send_string(json.dumps(jsonmessage))
|
||||
|
||||
# Create a unique correlation ID
|
||||
command = {
|
||||
"corrId": f"id{random.randint(0, 999999)}",
|
||||
"cmd": msg,
|
||||
}
|
||||
json_command = json.dumps(command)
|
||||
# Wait for a reply
|
||||
reply = socket.recv_string()
|
||||
print(f"Received reply: {reply}")
|
||||
|
||||
if reply == 'sent':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
""" Connects to WebSocket server, sends a message, and returns the response """
|
||||
# ws = websocket.create_connection(uri) # Blocking WebSocket connection
|
||||
ws.send(json_command) # Send message to WebSocket
|
||||
response = ws.recv() # Receive response
|
||||
# ws.close() # Close WebSocket connection
|
||||
print(response)
|
||||
return response
|
||||
|
||||
@app.route("/webhook/<id>", methods=['POST'])
|
||||
def webhook_receiver(id):
|
||||
print("Webhook id %s" % (id))
|
||||
pprint(request.json)
|
||||
data = request.json # Get the JSON data from the incoming request
|
||||
# Process the data and perform actions based on the event
|
||||
print("Received webhook data:", data)
|
||||
|
||||
target = hooks.get(id)
|
||||
print(target)
|
||||
sendmessage(target, data.get('message'))
|
||||
target = None
|
||||
for key, value in hooks.items():
|
||||
if str(key) == str(id):
|
||||
target = value
|
||||
|
||||
if target is not None:
|
||||
print(target)
|
||||
if data.get('message') is not None:
|
||||
sendmessage(target, data.get('message'))
|
||||
else:
|
||||
print("No message, droppint")
|
||||
else:
|
||||
print("No target found, dropping message")
|
||||
|
||||
return jsonify({'message': 'Webhook received successfully'}), 200
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
uri = "ws://localhost:5080"
|
||||
ws = websocket.create_connection(uri)
|
||||
app.run(debug=True)
|
||||
print("Started %s" % (versionstring))
|
||||
app.run()
|
||||
|
||||
13
server/tellme.service
Normal file
13
server/tellme.service
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Tellme Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=tellme
|
||||
WorkingDirectory=/opt/tellme
|
||||
Environment=FLASK_CONFIG=production
|
||||
ExecStart=waitress-serve --host=0.0.0.0 --port=8080 tellmesrv:app
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
12
server/tellme_notifier.service
Normal file
12
server/tellme_notifier.service
Normal file
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Tellme Notifier
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=tellme
|
||||
WorkingDirectory=/opt/tellme
|
||||
ExecStart=python3 notifier.py
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user