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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

infroger created an issue. See original summary.

jrockowitz’s picture

Yes, 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.

jrockowitz’s picture

Status: Active » Needs review

Yes, 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.

infroger’s picture

Thank 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

jrockowitz’s picture

Status: Needs review » Needs work

This 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.

jrockowitz’s picture

Via #2898424: Improve Remote Post I am going to add the ability to set custom request options which would include headers.

jrockowitz’s picture

Status: Needs work » Fixed
infroger’s picture

Have 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...

jrockowitz’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

oromero’s picture

@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.

infroger’s picture

@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.

igor.stamatovski’s picture

Is 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]

jrockowitz’s picture

Status: Closed (fixed) » Needs work
FileSize
4.64 KB
946 bytes

The attached webform replicates the issue and the attached patch fixes the issue.

jrockowitz’s picture

Version: 8.x-4.x-dev » 8.x-5.x-dev
jrockowitz’s picture

Status: Needs work » Needs review
jrockowitz’s picture

Attached patch adds test coverage.

jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download the latest dev release to review.

  • jrockowitz committed b534f74 on 8.x-5.x
    Issue #2894223 by jrockowitz, infroger: Custom HTTP Headers in Remote...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.