Hello eliot_jo,
Welcome to the Mattermost community! Great to have you here.
Your question is a common one, so don’t worry. To handle form submissions from an interactive dialog, you generally want to set up a separate endpoint in your Django application to process the POST request that’s sent when the dialog is submitted.
The submit_dialog
request, upon interactions like a user submitting the dialog or dropdown select, sends a POST
request to the callback_url
that you specified when opening the dialog.
Here’s a short example in pseudo code -
When you open the dialog, you define a dialog
object like so:
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14
dialog = { "callback_id": "somecallbackid", "url": "https://your-django-app.com/process-dialog", "title": "Dialog Title", "elements": [ { "type": "text", "name": "input_field_1", "label": "Input Field 1", }, ], "submit_label": "Submit", "notify_on_cancel": False, }
Notice the url
field in dialog, that’s where you’d put the endpoint in your Django application that you want Mattermost to send the POST request to when the dialog is submitted.
Then in your Django app, handle this at the endpoint process-dialog
:
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
`@require_POST
def process_dialog(request):
payload = json.loads(request.body)
submitted_data = payload[‘submission’]
# Now you have access to the submitted data.
# i.e - If your dialog had a field with the name "input_field_1",
# you can access its submitted value by - field_1_value = submitted_data['input_field_1']
# You can then do any processing you need with the submitted data.
# To send a message back to the channel you can use the 'response_url' provided in the payload.
# This will execute a POST request to the response_url and send the specified message to the channel.
response_message = {
"response_type": "in_channel",
"text": f"You submitted: {field_1_value}"
}
headers = {'Content-Type': 'application/json'}
requests.post(payload['response_url'], headers=headers, data=json.dumps(response_message))
return HttpResponse(status=200) # Respond with a 200 OK.`
That’s it! Before integrating it, please replace the placeholder URL with your actual application’s endpoint. I hope the above example helps you to move forward.
Just remember, the values you’re capturing in the dialog can be accessed in the payload of the POST request sent to the callback URL that you’ve defined.
If you have more questions or run into any issues, feel free to ask. We’re happy to help!
Best regards,
~Mattermost AI Assistant
[Disclaimer: This was an AI assisted response powered by Mattermost AI. Were any of the above suggestions inaccurate? Let us know by replying to this comment!]