Browse Source

Adding Content-Type header to Webhook integrations to work correctly with

services like https://ifttt.com/maker_webhooks which require a
specific content type, like application/json.
pull/140/head
someposer 7 years ago
parent
commit
0ea5927b6a
5 changed files with 36 additions and 3 deletions
  1. +6
    -0
      hc/api/models.py
  2. +5
    -2
      hc/api/transports.py
  3. +3
    -1
      hc/front/forms.py
  4. +6
    -0
      templates/front/channels.html
  5. +16
    -0
      templates/integrations/add_webhook.html

+ 6
- 0
hc/api/models.py View File

@ -321,6 +321,12 @@ class Channel(models.Model):
parts = self.value.split("\n")
return parts[2] if len(parts) > 2 else ""
@property
def content_type(self):
assert self.kind == "webhook"
parts = self.value.split("\n")
return parts[3] if len(parts) > 3 else ""
@property
def slack_team(self):
assert self.kind == "slack"


+ 5
- 2
hc/api/transports.py View File

@ -164,8 +164,11 @@ class Webhook(HttpTransport):
url = self.prepare(url, check, urlencode=True)
if self.channel.post_data:
headers = {}
if self.channel.content_type:
headers["Content-Type"] = self.channel.content_type
payload = self.prepare(self.channel.post_data, check)
return self.post(url, data=payload.encode("utf-8"))
return self.post(url, data=payload.encode("utf-8"), headers=headers)
else:
return self.get(url)
@ -230,7 +233,7 @@ class Pushbullet(HttpTransport):
url = "https://api.pushbullet.com/v2/pushes"
headers = {
"Access-Token": self.channel.value,
"Conent-Type": "application/json"
"Content-Type": "application/json"
}
payload = {
"type": "note",


+ 3
- 1
hc/front/forms.py View File

@ -65,9 +65,11 @@ class AddWebhookForm(forms.Form):
post_data = forms.CharField(max_length=1000, required=False)
content_type = forms.CharField(max_length=1000, required=False)
def get_value(self):
d = self.cleaned_data
return "\n".join((d["value_down"], d["value_up"], d["post_data"]))
return "\n".join((d["value_down"], d["value_up"], d["post_data"], d["content_type"]))
phone_validator = RegexValidator(regex='^\+\d{5,15}$',


+ 6
- 0
templates/front/channels.html View File

@ -80,6 +80,12 @@
<td>{{ ch.post_data }}</td>
</tr>
{% endif %}
{% if ch.content_type %}
<tr>
<td class="preposition">type&nbsp;</td>
<td>{{ ch.content_type }}</td>
</tr>
{% endif %}
</table>
{% elif ch.kind == "pushbullet" %}
<span class="preposition">API key</span>


+ 16
- 0
templates/integrations/add_webhook.html View File

@ -105,6 +105,22 @@
{% endif %}
</div>
</div>
<div class="form-group {{ form.content_type.css_classes }}">
<label class="col-sm-2 control-label">Content-Type</label>
<div class="col-sm-10">
<input
type="text"
class="form-control"
name="content_type"
placeholder='application/json'
value="{{ form.content_type.value|default:"" }}">
{% if form.content_type.errors %}
<div class="help-block">
{{ form.content_type.errors|join:"" }}
</div>
{% endif %}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Save Integration</button>


Loading…
Cancel
Save