working server/client
This commit is contained in:
parent
6650f0e042
commit
20ede6e02a
@ -1,5 +1,4 @@
|
||||
{
|
||||
"url": "",
|
||||
"webhook": "",
|
||||
"notify": "",
|
||||
"webhook": ""
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ def sendmessage(message):
|
||||
|
||||
url = ("%s/webhook/%s" % (baseurl, webhook))
|
||||
|
||||
r = requests.post(url, json = { 'message': mymessage, 'notify': notify, 'tts': args.tts })
|
||||
r = requests.post(url, json = { 'message': mymessage })
|
||||
if r.status_code == 200:
|
||||
print("Message has been sent successfully")
|
||||
# print(message)
|
||||
@ -49,10 +49,8 @@ home=os.getenv("HOME")
|
||||
|
||||
parser = argparse.ArgumentParser(description='TellMe command line client')
|
||||
parser.add_argument("-m", "--message", default="Your process finished", help="Message to send")
|
||||
parser.add_argument('-t', '--tts', default=False, action='store_true', help="Send message to TTS")
|
||||
parser.add_argument('-v', '--version', action='version', version=versionstring)
|
||||
parser.add_argument('-p', '--pid', action="store", dest="pid", type=int, default=0)
|
||||
parser.add_argument('-n', '--notify', action="store", dest="notify", default=None, help="Notify specific id")
|
||||
parser.add_argument('-i', '--interval', action="store", dest="interval", type=int, default=5, help="Set the interval of commands like watch that use it")
|
||||
parser.add_argument('-w', '--watch', action="store", dest="watchcommand", help="Run the given command every n or 5 minutes")
|
||||
parser.add_argument('-c', '--config', default=home +"/.config/tellme/config.json" ,help="Path to config file")
|
||||
|
@ -7,8 +7,11 @@ import random
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
hooks = {}
|
||||
hooks['2345555XE'] = '#Bottest'
|
||||
|
||||
def sendmessage(target, message):
|
||||
print("Sendmessage called")
|
||||
print("Sendmessage %s called to %s" % (message, target))
|
||||
uri = "ws://localhost:5080"
|
||||
#message = "#Bottest Hello, world!"
|
||||
msg = ("%s %s" % (target, message))
|
||||
@ -28,18 +31,19 @@ def sendmessage(target, message):
|
||||
print(response)
|
||||
return response
|
||||
|
||||
@app.route('/webhook', methods=['POST'])
|
||||
def webhook_receiver():
|
||||
@app.route("/webhook/<id>", methods=['POST'])
|
||||
def webhook_receiver(id):
|
||||
print("Webhook id %s" % (id))
|
||||
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'))
|
||||
|
||||
return jsonify({'message': 'Webhook received successfully'}), 200
|
||||
|
||||
@app.route('/webhook', methods=['GET'])
|
||||
def webhook_test():
|
||||
print("Sending test")
|
||||
sendmessage('#Bottest', 'Testing 123')
|
||||
return jsonify({'message': 'Webhook received successfully'}), 200
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
Loading…
Reference in New Issue
Block a user