Hi,
I'm new to Drupal and the Drupal Community, and apologize in advance for any error opening this issue.
I want to submit a weform submission to a Rocket.Chat (a Slack competitor) channel. I'm almost there. Just didn't find how to send CUSTOM HTTP HEADER with authentication and authorization data (X-Auth-Token and X-User-Id). See attached image and URL below.
https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage
What is the best approach:
1. Is Custom HTTP Header available and I didn't find?
2. Should I extend RemotePostWebformHandler? Is there a reference on how to do it?
3. For a quick solution, I'm thinking of writting a PHP script that would sit in the middle. Webform would POST to this script and this script would then add the headers and submit to Rocket.Chat.
Regards,
Roger
Comment | File | Size | Author |
---|---|---|---|
#17 | 2894223-17.patch | 2.45 KB | jrockowitz |
| |||
#14 | 2894223-2.patch | 946 bytes | jrockowitz |
| |||
#14 | webform.webform.issue_289422_custom_http_headers.yml | 4.64 KB | jrockowitz |
D078.png | 66.73 KB | infroger |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedYes, you should extend the RemotePostWebformHandler. There is no specific reference available, you just need to understand how to work with plugins in Drupal 8. Take a look at the Examples module.
You should consider contributing your Rocket Chat webform handler back to the Drupal community.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedYes, you should extend the RemotePostWebformHandler. There is no specific reference available, you just need to understand how to work with plugins in Drupal 8. Take a look at the Examples module.
You should consider contributing your Rocket Chat webform handler back to the Drupal community.
Comment #4
infroger CreditAttribution: infroger commentedThank you Jacob.
I'll take the extend RemotePostWebformHandler as a future solution, since I don't know how to work with plugins in Drupal 8. Once I have it, will contribute.
I just have a short time and will implement a script in the middle to add the custom headers.
Regards,
Roger
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThis might be a bad idea but we could allow custom request options to be applied to each remote post. I could see allowing form builders to enter custom request options as YAML.
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedVia #2898424: Improve Remote Post I am going to add the ability to set custom request options which would include headers.
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@see #2898424: Improve Remote Post
Comment #8
infroger CreditAttribution: infroger commentedHave tested and it worked! Thank you very much Jacob! And congratulations for the excelent job supporting Druppal Webforms. Have written an article detailing the integration: https://rogerkrolow.blogspot.com.br/2017/07/integrating-drupal-8-webform...
Comment #9
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@infroger I added your blog post to https://www.drupal.org/docs/8/modules/webform/webform-introduction
Comment #11
oromero CreditAttribution: oromero commented@infroger it is not clear if you created a custom handler, plugin by extending RemotePostWebformHandler?
- The screenshots that you put in the blogspot looks like it is a custom handler.
- If you created a custom handler. Will be great if you post your code in some place.
Comment #12
infroger CreditAttribution: infroger commented@oromero, I did not create a plugin. I applied @jrockowitz patch and used the new "Custom Options" setting to add the headers needed for the request.
Comment #13
igor.stamatovski CreditAttribution: igor.stamatovski commentedIs there a possibility to use Submission data tokens to send the language code as Accept-Language for the custom options YAML array.
Custom Options:
headers:
Accept-Language: [webform:handler:remote_post:langcode]
Comment #14
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached webform replicates the issue and the attached patch fixes the issue.
Comment #15
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #16
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #17
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedAttached patch adds test coverage.
Comment #18
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed the patch. Please download the latest dev release to review.