Reputation: 388
I'm working on a webhook that sends Telegrams messages to Slack and Slack messages to Telegram; right now I can send Telegram messages to Slack but I can't send from Slack to Telegram because I don't know how to get the data. As the Slack documentation states, the data sent on the POST request is like this:
token=XXXXXXXXXXXXXXXXXX
team_id=T0001
team_domain=example
channel_id=C2147483705
channel_name=test
timestamp=1355517523.000005
user_id=U2147483697
user_name=Steve
text=googlebot: What is the air-speed velocity of an unladen swallow?
trigger_word=googlebot:
The content type is application/x-www-form-urlencoded
From that data I want to get the user_name
and text
On my Flask code I don't have nothing because I don't know how to receive that data or how can I see it on the console so I could try to extract it and send it to Telegram, this is the only thing that I have for the Slack webhook just because I wanted to see if it was working, I think that these lines of code are not relevant right now:
@app.route("/" + SLACK, methods=['POST'])
def slack_handler():
if request.method == "POST":
return "POST"
And that's my problem; how can I receive, store that data? if I should explain more my issue please let me know and thanks for any help.
Upvotes: 0
Views: 800
Reputation: 652
As long as your slack webhook is configured appropriately you should be able to treat it like a form. The following should work-
from flask import Flask, request
slack_webhook = your_webhook_here
@app.route('/slack', methods=['POST'])
def slack():
if request.form.get('token') == slack_webhook:
channel = request.form.get('channel')
username = request.form.get('username')
return "Channel: " + channel + "Username: " + username
else:
return "None found"
Read this post for more on this- realpython.com
Upvotes: 1