webhooks: Create Intercom integration and docs.

This commit is contained in:
Viraat Chandra
2018-01-06 16:41:44 +05:30
committed by showell
parent 8c5e74afe9
commit 64034241a0
9 changed files with 163 additions and 75 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 KiB

View File

@@ -0,0 +1 @@
<svg width="1.6667in" height="1.6667in" clip-rule="evenodd" fill-rule="evenodd" image-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" version="1.1" viewBox="0 0 1667 1667" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path fill-rule="nonzero" fill="#1F8DED" d="m1444 916c0 31-25 56-56 56s-56-25-56-56v-500c0-31 25-56 56-56s56 25 56 56v500zm-1444-708v1250c0 115 93 208 208 208h1250c115 0 208-93 208-208v-1250c0-115-93-208-208-208h-1250c-115 0-208 93-208 208zm1425 1056c-9 7-214 180-592 180-377 0-583-173-592-180-23-20-26-55-6-78s55-26 78-6c3 3 187 153 520 153 337 0 518-152 519-153 23-20 58-17 78 6s17 58-6 78zm-1203-847c0-31 25-56 56-56s56 25 56 56v500c0 31-25 56-56 56s-56-25-56-56v-500zm278-111c0-31 25-56 56-56s56 25 56 56v742c0 31-25 56-56 56s-56-25-56-56v-742zm278-28c0-31 25-56 56-56s56 25 56 56v806c0 31-25 56-56 56s-56-25-56-56v-806zm278 28c0-31 25-56 56-56s56 25 56 56v742c0 31-25 56-56 56s-56-25-56-56v-742z"/></svg>

After

Width:  |  Height:  |  Size: 991 B

View File

@@ -325,6 +325,7 @@ WEBHOOK_INTEGRATIONS = [
function='zerver.webhooks.ifttt.view.api_iftt_app_webhook',
display_name='IFTTT'
),
WebhookIntegration('intercom', ['customer-support'], display_name='Intercom'),
WebhookIntegration('jira', ['project-management'], display_name='JIRA'),
WebhookIntegration('librato', ['monitoring']),
WebhookIntegration('mention', ['marketing'], display_name='Mention'),

View File

View File

@@ -0,0 +1,33 @@
{!create-stream.md!}
{!create-bot-construct-url.md!}
Intercom will use the `intercom` stream by default if no stream is given
in the URL. Make sure the selected stream exists in Zulip.
**Follow these steps:**
1. Go to the Integrations Page of your Intercom Console.
2. Find and select the `Zapier` integration option.
3. Create an account on `Zapier` if you haven't
already. Click on **Explore Intercom on Zapier!**.
4. Select **Make A ZAP**. Choose `Intercom `in the apps section and
`Webhooks` in the built-in apps section.
5. Authenticate with your Intercom account to connect it with
`Zapier`.
6. Select the actions which will trigger the webhook.
7. Select **POST** on the page that says **Webhooks by Zapier Action**, and
click **Continue**.
8. In the **URL** field, enter the URL constructed above. Select `JSON`
for **Payload Type** and click **Continue**:
{!congrats.md!}
![](/static/images/integrations/intercom/001.png)

View File

@@ -1,75 +0,0 @@
{
"type" : "notification_event",
"app_id" : "vsahmbmw",
"data" : {
"type" : "notification_event_data",
"item" : {
"type" : "user_tag",
"user" : {
"type" : "user",
"id" : "5a364a4a4716ab4dc29e87ba",
"user_id" : "5",
"anonymous" : false,
"email" : "a@b.com",
"phone" : null,
"name" : "e",
"pseudonym" : null,
"avatar" : {
"type" : "avatar",
"image_url" : null
},
"app_id" : "vsahmbmw",
"companies" : {
"type" : "company.list",
"companies" : [ ]
},
"location_data" : { },
"last_request_at" : null,
"last_seen_ip" : null,
"created_at" : "2017-12-17T10:43:22.000Z",
"remote_created_at" : null,
"signed_up_at" : null,
"updated_at" : "2017-12-17T10:43:22.496Z",
"session_count" : 0,
"social_profiles" : {
"type" : "social_profile.list",
"social_profiles" : [ ]
},
"unsubscribed_from_emails" : false,
"marked_email_as_spam" : false,
"has_hard_bounced" : false,
"user_agent_data" : null,
"tags" : {
"type" : "tag.list",
"tags" : [ {
"type" : "tag",
"id" : "1449318"
} ]
},
"segments" : {
"type" : "segment.list",
"segments" : [ ]
},
"custom_attributes" : { }
},
"tag" : {
"type" : "tag",
"id" : "1449318",
"name" : "CSV Import - 2017-12-17 10:42:59 UTC"
},
"created_at" : 1513507402,
"admin" : {
"type" : "admin"
}
}
},
"links" : { },
"id" : "notif_1a6fd8a0-e317-11e7-b721-d77135370663",
"topic" : "user.tag.created",
"delivery_status" : "pending",
"delivery_attempts" : 1,
"delivered_at" : 0,
"first_sent_at" : 1513507402,
"created_at" : 1513507402,
"self" : null
}

View File

@@ -0,0 +1,77 @@
{
"type": "notification_event",
"app_id": "vsahmbmw",
"data": {
"type": "notification_event_data",
"item": {
"type": "user_tag",
"user": {
"type": "user",
"id": "5a364a4a4716ab4dc29e87ba",
"user_id": "5",
"anonymous": false,
"email": "john.doe@gmail.com",
"phone": 9876543211,
"name": "John Doe",
"pseudonym": null,
"avatar": {
"type": "avatar",
"image_url": null
},
"app_id": "vsahmbmw",
"companies": {
"type": "company.list",
"companies": []
},
"location_data": {},
"last_request_at": null,
"last_seen_ip": null,
"created_at": "2017-12-17T10:43:22.000Z",
"remote_created_at": null,
"signed_up_at": null,
"updated_at": "2017-12-17T10:43:22.496Z",
"session_count": 0,
"social_profiles": {
"type": "social_profile.list",
"social_profiles": []
},
"unsubscribed_from_emails": false,
"marked_email_as_spam": false,
"has_hard_bounced": false,
"user_agent_data": null,
"tags": {
"type": "tag.list",
"tags": [
{
"type": "tag",
"id": "1449318"
}
]
},
"segments": {
"type": "segment.list",
"segments": []
},
"custom_attributes": {}
},
"tag": {
"type": "tag",
"id": "1449318",
"name": "CSV Import - 2017-12-17 10:42:59 UTC"
},
"created_at": 1513507402,
"admin": {
"type": "admin"
}
}
},
"links": {},
"id": "notif_1a6fd8a0-e317-11e7-b721-d77135370663",
"topic": "user.tag.created",
"delivery_status": "pending",
"delivery_attempts": 1,
"delivered_at": 0,
"first_sent_at": 1513507402,
"created_at": 1513507402,
"self": null
}

View File

@@ -0,0 +1,21 @@
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class IntercomWebHookTests(WebhookTestCase):
STREAM_NAME = 'test'
URL_TEMPLATE = "/api/v1/external/intercom?&api_key={api_key}&stream={stream}"
FIXTURE_DIR_NAME = 'intercom'
def test_user_created_message(self) -> None:
expected_subject = u"user tag created"
expected_message = ('*10:43:22 2017-12-17* **user tag created**: \n'
' - User Name: John Doe\n'
' - User Email: john.doe@gmail.com\n'
' - User Phone: 9876543211')
self.send_and_test_stream_message('user_created', expected_subject, expected_message,
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name: Text) -> Text:
return self.fixture_data('intercom', fixture_name, file_type="json")

View File

@@ -0,0 +1,30 @@
import datetime
from typing import Any, Dict, Text
from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view
from zerver.lib.actions import check_send_stream_message
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.models import UserProfile
@api_key_only_webhook_view('Intercom')
@has_request_variables
def api_intercom_webhook(request: HttpRequest, user_profile: UserProfile,
payload: Dict[str, Any] = REQ(argument_type='body'),
stream: Text = REQ(default='intercom')) -> HttpResponse:
topic = payload['topic']
topic = topic.replace('.', ' ')
created_at = datetime.datetime.fromtimestamp(int(payload['created_at'])).strftime('%H:%M:%S %Y-%m-%d')
body = '*{created_at}* **{topic}**: \n'.format(topic=topic, created_at=created_at)
if payload['data']['item']['type'] == 'user_tag':
data = payload['data']['item']['user']
body += ' - User Name: {}\n' \
' - User Email: {}\n' \
' - User Phone: {}\n'.format(data['name'], data['email'], data['phone'])
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()