From 9e52a9f879b72ca064840652597ced0295548916 Mon Sep 17 00:00:00 2001 From: Ricky Date: Thu, 1 Mar 2018 16:43:15 +0530 Subject: [PATCH] webhooks/flock: Add flock integration. --- static/images/integrations/flock/001.png | Bin 0 -> 6814 bytes static/images/integrations/logos/flock.png | Bin 0 -> 3657 bytes zerver/lib/integrations.py | 1 + zerver/webhooks/flock/__init__.py | 0 zerver/webhooks/flock/doc.md | 17 ++++ zerver/webhooks/flock/fixtures/messages.json | 11 +++ zerver/webhooks/flock/fixtures/note.json | 26 +++++ zerver/webhooks/flock/fixtures/pinned.json | 17 ++++ zerver/webhooks/flock/fixtures/reminder.json | 40 ++++++++ zerver/webhooks/flock/fixtures/reply.json | 20 ++++ .../webhooks/flock/fixtures/reply_note.json | 20 ++++ .../webhooks/flock/fixtures/reply_pinned.json | 20 ++++ .../flock/fixtures/reply_reminder.json | 20 ++++ .../webhooks/flock/fixtures/reply_todo.json | 20 ++++ zerver/webhooks/flock/fixtures/todo.json | 49 ++++++++++ zerver/webhooks/flock/tests.py | 90 ++++++++++++++++++ zerver/webhooks/flock/view.py | 26 +++++ 17 files changed, 377 insertions(+) create mode 100644 static/images/integrations/flock/001.png create mode 100644 static/images/integrations/logos/flock.png create mode 100644 zerver/webhooks/flock/__init__.py create mode 100644 zerver/webhooks/flock/doc.md create mode 100644 zerver/webhooks/flock/fixtures/messages.json create mode 100644 zerver/webhooks/flock/fixtures/note.json create mode 100644 zerver/webhooks/flock/fixtures/pinned.json create mode 100644 zerver/webhooks/flock/fixtures/reminder.json create mode 100644 zerver/webhooks/flock/fixtures/reply.json create mode 100644 zerver/webhooks/flock/fixtures/reply_note.json create mode 100644 zerver/webhooks/flock/fixtures/reply_pinned.json create mode 100644 zerver/webhooks/flock/fixtures/reply_reminder.json create mode 100644 zerver/webhooks/flock/fixtures/reply_todo.json create mode 100644 zerver/webhooks/flock/fixtures/todo.json create mode 100644 zerver/webhooks/flock/tests.py create mode 100644 zerver/webhooks/flock/view.py diff --git a/static/images/integrations/flock/001.png b/static/images/integrations/flock/001.png new file mode 100644 index 0000000000000000000000000000000000000000..496f52f1a068d0d7ac7b8b152305707d354b08eb GIT binary patch literal 6814 zcmX|`2RIyGw7`iVdTcDwgCJ`3-a?3;h{Y;P)YUsHdenrl5u*1NZ5PpZqXbc+i{5)% zJ<+Ya^?&bs^LJ?H$+ocZud_XPzh11TOJ9)*Vb^VfKIckFT3ukI1yjtJuq zxwsR)*XtL`c*sGfZCv3l^qI~xJiKZ+*|jAhu1w;tZtR7JN7-?^<9EB2*x+umd8>lG zRXlAiy&c?KAAuZPZ1F^dgr#JJL}i3T9tjJ{h>6IEOFOZ-f55|IAkujL4CH6NHy_{! zTF)XrJTL=%zW?a{Jz92=iDWDB*Ba$!{?qU4;C1iHFf*>&E}ip1fsRYlu8>lz9AN20 zNF&X*Z)DQXisn+zk;@8+V!m|ycTbkSkWyL!9uKH13$96sUfnGG$?nwp1otNFNng1V-pkw2ly{+08A3a$}Ap}^F8vNODS-Or!~Z7oo52ScIU=@}Uw$7>q$;t~=f zxwsBfX&ZoI!l@aAo|ENm?0Kp$&)yiLjE_h>^HIP0>9_mb;bue4eV^>oYo#|c*2VbI zFdAe7l0hCWr+LN9d0b^hVkaOVAXB1~E~a5*V5=Z3Ol@9ij&`FN^lyC)izUyk(?+qYNc{kVDcR zGbC(PRBirh1Ps-VMbyu{HR% zR5WiePL95l3@7H8xl3Qw)47nsfLd75hyu)^^($xqWQp1PHaKIni2ZfMd;s%Co8+X; zOuQxUzD(T|yZ2h$$;Cz0)AJjpm4=1}%8|=*V9)o3>!XBFE|-d8oV36qZGcY9uqJ0#}Q?n(Qg z4J;`ud%0B$mrA?*goY2X1E2)pepYg(tjdj^O^Vh1pQocEp zp$pSRe6S|TRHgJ5a>+6w<2u_E4tweNjD*tUvR4ppG6$)Uc>lM1Pp7^TWXR-XzSUEH zW5LYKj3U$LwH47g{LGv7=?xd=acA#id|h7WZ*lw&a1$o%xMy#8FW}l0&8V+K7@$`=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YoS3a@eJ!$%wT(iLR_U(k>!eY=fl< zP59dl7TglRDsrjgWSXek`e)YSP0yFCrEtu7_J%NSOZyXAHek*t9hXSJ`h?>$oIch{ z|C?3WU3rY7!T)DhaJd)mTfk?@;@ZM(|DRuZu>IeI`R8q<|7BLp@NZao%-UpmRW4d^ QzmM=VRCS*tmEVN@5B}Ll?EnA( literal 0 HcmV?d00001 diff --git a/static/images/integrations/logos/flock.png b/static/images/integrations/logos/flock.png new file mode 100644 index 0000000000000000000000000000000000000000..b96bd2803bbc677169aa1002221054a5caf53ac7 GIT binary patch literal 3657 zcmV-P4z}@$P)gwv{<>lbu;N;}w+uPgN*x1Fz#nsi-zrVlD&CRi~ zv7n%!_x<_+yh`r-^^o4I3By`W%Xo#_qTKf8xVX4~*`BSft>X9UXxEdx>&-~ZchB%k2ROc=TTDl%Zq*KHQnJ`lA#4@M3%J`9NZ zv;JYu`7YwD9WF!+*lZ#LBLDn&z6SPHjEKz0ibyO-VpXSIbmM@ecA{9%))|Qf^%e@C zwJ=~LP47KCHTP#9fS=z3pVdY&p9%2?@UuhcyHqyBC`+I&*!$EJm@Tbu^gFFQL}Ec) z#MC9mJS#?|M$`n*sGEyMQhNq=REiO!G=Tv1GTQ~HX3szomExzkl4*5%MyFO$^jW%L zpuC6>)BktmqsW=-7iAJ@9ixY%O@uGQZD#o?F=5Z_)i#bM>JEEdY{b{kV-pVRnhJlU z4%3Yoo6xMi2^)=GY{cIvQ6M#}dI!=-O^X=ul@R4ZWWr(118F347=_bcA4Vn|8Wpt( zR$a?@b5jy$`u~QLVmC!O@x@IMA#u_=7i>RLhwpA06>LMZ$Zlxg+~smPo1s74n_b|8 z8d@)Q)924r;-tl-dwY5EujA=;16xItRd-$PalzPIJ97EQv0-9h29U?yBrJ~ z2IIX8`rt+rb;RzkvIYkl)D11TlFfGg#hC{8%;`Ac>Hz7n?cr-jMEM?PLklRB+ROd; ztT53%L2i98NYzAT%?lwZ*@hrB#*<=Y% ztD}VZo*0$ML2?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-00000NkvXXu0mjfmkjlT literal 0 HcmV?d00001 diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index f7266d201f..1ba2b0cd99 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -293,6 +293,7 @@ WEBHOOK_INTEGRATIONS = [ stream_name='desk' ), WebhookIntegration('dropbox', ['productivity'], display_name='Dropbox'), + WebhookIntegration('flock', ['customer-support'], display_name='Flock'), WebhookIntegration('freshdesk', ['customer-support']), WebhookIntegration('front', ['customer-support'], display_name='Front'), GithubIntegration( diff --git a/zerver/webhooks/flock/__init__.py b/zerver/webhooks/flock/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/webhooks/flock/doc.md b/zerver/webhooks/flock/doc.md new file mode 100644 index 0000000000..7277c099f0 --- /dev/null +++ b/zerver/webhooks/flock/doc.md @@ -0,0 +1,17 @@ +Get Zulip notifications from your Flock channels. + +1. {!create-stream.md!} + +1. {!create-bot-construct-url-indented.md!} + +1. Click on **Apps** in the bottom-right corner. + Click on **Admin Panel**, and click on **Webhooks**. + Next to **Outgoing Webhook**, click on **Add**. + +1. Set **Send messages from a channel** to the channel you'd like to be notified about. + Set **Name that the webhook will post as** to a name of your choice, such as `Zulip`. + Set **Callback URL** to the URL created above, and click **Save Settings**. + +{!congrats.md!} + +![](/static/images/integrations/flock/001.png) diff --git a/zerver/webhooks/flock/fixtures/messages.json b/zerver/webhooks/flock/fixtures/messages.json new file mode 100644 index 0000000000..acea1faa87 --- /dev/null +++ b/zerver/webhooks/flock/fixtures/messages.json @@ -0,0 +1,11 @@ +{ + "id": "1519889547187_0", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:9qehqo3ixo3t93e3", + "text": "This is the welcome message!", + "timestamp": "2018-03-01T07:32:25.238Z", + "timestampInMillis": 1519889545238, + "uid": "1519889545238-gg8-m203", + "onBehalfOf": "", + "visibleTo": [] +} diff --git a/zerver/webhooks/flock/fixtures/note.json b/zerver/webhooks/flock/fixtures/note.json new file mode 100644 index 0000000000..2d7e8f22a6 --- /dev/null +++ b/zerver/webhooks/flock/fixtures/note.json @@ -0,0 +1,26 @@ +{ + "attachments": [ + { + "appId": "bd05fb5b1e39e29b396e03c2efe053196e3b9458", + "title": "NoteTitle", + "forward": true, + "views": { + "widget": { + "src": "https://apps.flock.co:443/flock-notes/notes/8a0fc0c2-e567-4685-a7a7-883898da47c3/preview", + "width": 0, + "height": 65 + } + } + } + ], + "id": "Amreh", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:9qehqo3ixo3t93e3", + "notification": "Shared a note", + "text": "", + "appId": "bd05fb5b1e39e29b396e03c2efe053196e3b9458", + "timestamp": "2018-03-01T08:16:08.335Z", + "timestampInMillis": 1519892168335, + "uid": "1519892168335-y7J-m203", + "onBehalfOf": "" +} diff --git a/zerver/webhooks/flock/fixtures/pinned.json b/zerver/webhooks/flock/fixtures/pinned.json new file mode 100644 index 0000000000..64788bb27d --- /dev/null +++ b/zerver/webhooks/flock/fixtures/pinned.json @@ -0,0 +1,17 @@ +{ + "id": "SMzzJ", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:9qehqo3ixo3t93e3", + "notification": "Rishabh rawat pinned an item to the conversation", + "flockml": "Rishabh rawat pinned an item to this conversation. You can access it via the Files App.", + "text": "", + "sendAs": { + "name": "Pinner Bot", + "profileImage": "https://apps-static.flock.co/smartbar/bot-icon.png" + }, + "appId": "6937451c-edbf-4ecb-b715-1e26574b5168", + "timestamp": "2018-03-01T07:49:06.284Z", + "timestampInMillis": 1519890546284, + "uid": "1519890546284-f3t-m203", + "onBehalfOf": "" +} diff --git a/zerver/webhooks/flock/fixtures/reminder.json b/zerver/webhooks/flock/fixtures/reminder.json new file mode 100644 index 0000000000..5b92648540 --- /dev/null +++ b/zerver/webhooks/flock/fixtures/reminder.json @@ -0,0 +1,40 @@ +{ + "attachments": [ + { + "id": "3d5774d9-ec8e-4664-9286-c54d0034e401", + "appId": "905f9943396442448b5d259d72c6d5fe", + "title": "FlockBot undefined in mychannel: Hey ", + "color": "#efb80b", + "forward": false, + "buttons": [ + { + "name": "Snooze for me", + "icon": "https://apps-static.flock.co/reminder/snooze.svg", + "action": { + "mobileType": "modal", + "type": "openWidget", + "desktopType": "modal", + "url": "https://apps-static.flock.co/reminder3/production/html/snooze.html", + "width": 570, + "height": 270, + "sendContext": false + }, + "id": "22841" + } + ] + } + ], + "id": "wzXJN", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:Bu4v779hlh4uuug5", + "text": "Rishabh rawat wanted me to remind All", + "sendAs": { + "name": "Reminder Bot", + "profileImage": "https://apps-static.flock.co/reminder/reminder-bot.png" + }, + "appId": "905f9943396442448b5d259d72c6d5fe", + "timestamp": "2018-03-01T08:00:03.587Z", + "timestampInMillis": 1519891203587, + "uid": "1519891203587-Nhj-m201", + "onBehalfOf": "u:9qehqo3ixo3t93e3" +} diff --git a/zerver/webhooks/flock/fixtures/reply.json b/zerver/webhooks/flock/fixtures/reply.json new file mode 100644 index 0000000000..a21e26da58 --- /dev/null +++ b/zerver/webhooks/flock/fixtures/reply.json @@ -0,0 +1,20 @@ +{ + "attachments": [ + { + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "title": "in reply to Rishabh R", + "description": "This is the welcome message!", + "color": "#0BBE51", + "forward": false + } + ], + "id": "BPsjQ", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:9qehqo3ixo3t93e3", + "text": "It's interesting how high productivity will go...", + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "timestamp": "2018-03-01T07:44:45.493Z", + "timestampInMillis": 1519890285493, + "uid": "1519890285493-eed-m203", + "onBehalfOf": "" +} diff --git a/zerver/webhooks/flock/fixtures/reply_note.json b/zerver/webhooks/flock/fixtures/reply_note.json new file mode 100644 index 0000000000..37c6664a75 --- /dev/null +++ b/zerver/webhooks/flock/fixtures/reply_note.json @@ -0,0 +1,20 @@ +{ + "attachments": [ + { + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "title": "in reply to Rishabh R", + "description": "NoteTitle", + "color": "#0BBE51", + "forward": false + } + ], + "id": "WPDlW", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:9qehqo3ixo3t93e3", + "text": "This is reply to Note.", + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "timestamp": "2018-03-01T08:16:57.793Z", + "timestampInMillis": 1519892217793, + "uid": "1519892217793-lt2-m203", + "onBehalfOf": "" +} diff --git a/zerver/webhooks/flock/fixtures/reply_pinned.json b/zerver/webhooks/flock/fixtures/reply_pinned.json new file mode 100644 index 0000000000..33db7482ec --- /dev/null +++ b/zerver/webhooks/flock/fixtures/reply_pinned.json @@ -0,0 +1,20 @@ +{ + "attachments": [ + { + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "title": "in reply to Rishabh R", + "description": "Rishabh rawat pinned an item to this conversation. You can access it via the Files", + "color": "#0BBE51", + "forward": false + } + ], + "id": "QPJia", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:9qehqo3ixo3t93e3", + "text": "This is reply to pinned message.", + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "timestamp": "2018-03-01T08:11:46.549Z", + "timestampInMillis": 1519891906549, + "uid": "1519891906549-rzZ-m203", + "onBehalfOf": "" +} diff --git a/zerver/webhooks/flock/fixtures/reply_reminder.json b/zerver/webhooks/flock/fixtures/reply_reminder.json new file mode 100644 index 0000000000..0dc4f36002 --- /dev/null +++ b/zerver/webhooks/flock/fixtures/reply_reminder.json @@ -0,0 +1,20 @@ +{ + "attachments": [ + { + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "title": "in reply to Reminders B", + "description": "Rishabh rawat wanted me to remind All", + "color": "#0BBE51", + "forward": false + } + ], + "id": "Oprnr", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:9qehqo3ixo3t93e3", + "text": "This is a reply to Reminder.", + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "timestamp": "2018-03-01T08:14:17.985Z", + "timestampInMillis": 1519892057985, + "uid": "1519892057985-B1f-m203", + "onBehalfOf": "" +} diff --git a/zerver/webhooks/flock/fixtures/reply_todo.json b/zerver/webhooks/flock/fixtures/reply_todo.json new file mode 100644 index 0000000000..597582e5be --- /dev/null +++ b/zerver/webhooks/flock/fixtures/reply_todo.json @@ -0,0 +1,20 @@ +{ + "attachments": [ + { + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "title": "in reply to To-do bot", + "description": "Study for end term exams.", + "color": "#0BBE51", + "forward": false + } + ], + "id": "WoBGB", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:9qehqo3ixo3t93e3", + "text": "This is a reply to Todo notification.", + "appId": "7d7d0856-f0a1-45bc-a66e-8c9ed504e620", + "timestamp": "2018-03-01T08:13:24.950Z", + "timestampInMillis": 1519892004950, + "uid": "1519892004950-1re-m203", + "onBehalfOf": "" +} diff --git a/zerver/webhooks/flock/fixtures/todo.json b/zerver/webhooks/flock/fixtures/todo.json new file mode 100644 index 0000000000..9bea25f4e3 --- /dev/null +++ b/zerver/webhooks/flock/fixtures/todo.json @@ -0,0 +1,49 @@ +{ + "attachments": [ + { + "id": "todo_attachment", + "appId": "6d0aa37b00944ec0a7426d34ca2df048", + "color": "#2A83Fc", + "views": { + "flockml": "Study for end term exams." + }, + "buttons": [ + { + "name": "View", + "action": { + "mobileType": "modal", + "type": "openWidget", + "desktopType": "sidebar", + "url": "https://apps-static.flock.co/todo/index.html?type=chat&chat&chatName=mychannel&listId=li%3Ac5f13a8a-e90a-4396-b810-1cfe85ef7c31&todoId=to%3Ab4273700-ac8c-44d0-91a3-d13d3d11e500", + "sendContext": false + }, + "id": "view" + }, + { + "name": "Mark as done", + "icon": "https://apps-static.flock.com/todo/markasdone.svg", + "action": { + "type": "sendEvent", + "sendContext": false + }, + "id": "complete;g:183ff1e90d79465793273a31d7d1e537;li:c5f13a8a-e90a-4396-b810-1cfe85ef7c31;to:b4273700-ac8c-44d0-91a3-d13d3d11e500" + } + ] + } + ], + "id": "LrAbZ", + "to": "g:183ff1e90d79465793273a31d7d1e537", + "from": "u:Bgcq3pt33pqpllbt", + "notification": "Rishabh rawat added a to-do in New List 1 list", + "flockml": "Rishabh rawat added a to-do in New List 1 list", + "text": "", + "sendAs": { + "name": "To-do bot", + "profileImage": "https://apps-static.flock.com/todo/todoboticon.png" + }, + "appId": "6d0aa37b00944ec0a7426d34ca2df048", + "timestamp": "2018-03-01T07:56:41.413Z", + "timestampInMillis": 1519891001413, + "uid": "1519891001413-vNe-m201", + "onBehalfOf": "u:9qehqo3ixo3t93e3" +} diff --git a/zerver/webhooks/flock/tests.py b/zerver/webhooks/flock/tests.py new file mode 100644 index 0000000000..ae6f9ba8ff --- /dev/null +++ b/zerver/webhooks/flock/tests.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +from typing import Text +from zerver.lib.test_classes import WebhookTestCase + +class FlockHookTests(WebhookTestCase): + STREAM_NAME = 'test' + URL_TEMPLATE = u"/api/v1/external/flock?api_key={api_key}" + + def test_flock_message(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"This is the welcome message!" + self.send_and_test_stream_message('messages', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_reply(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"It's interesting how high productivity will go..." + self.send_and_test_stream_message('reply', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_note(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"Shared a note" + self.send_and_test_stream_message('note', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_reply_note(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"This is reply to Note." + self.send_and_test_stream_message('reply_note', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_reply_pinned(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"This is reply to pinned message." + self.send_and_test_stream_message('reply_pinned', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_reply_reminder(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"This is a reply to Reminder." + self.send_and_test_stream_message('reply_reminder', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_reply_todo(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"This is a reply to Todo notification." + self.send_and_test_stream_message('reply_todo', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_pinned(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"Rishabh rawat pinned an item to the conversation" + self.send_and_test_stream_message('pinned', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_reminder(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"Rishabh rawat wanted me to remind All" + self.send_and_test_stream_message('reminder', + expected_subject, + expected_message, + content_type="application/json") + + def test_flock_todo(self) -> None: + expected_subject = u"Flock notifications" + expected_message = u"Rishabh rawat added a to-do in New List 1 list" + self.send_and_test_stream_message('todo', + expected_subject, + expected_message, + content_type="application/json") + + def get_body(self, fixture_name: Text) -> Text: + return self.fixture_data("flock", fixture_name, file_type="json") diff --git a/zerver/webhooks/flock/view.py b/zerver/webhooks/flock/view.py new file mode 100644 index 0000000000..c7ce376a68 --- /dev/null +++ b/zerver/webhooks/flock/view.py @@ -0,0 +1,26 @@ +# Webhooks for external integrations. +from zerver.lib.actions import check_send_stream_message +from zerver.lib.response import json_success +from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view +from zerver.models import UserProfile +from django.http import HttpRequest, HttpResponse +from typing import Dict, Any, Text + +CHECK_IS_REPLY = "in reply to" + +@api_key_only_webhook_view('Flock') +@has_request_variables +def api_flock_webhook(request: HttpRequest, user_profile: UserProfile, + payload: Dict[str, Any]=REQ(argument_type='body'), + stream: str=REQ(default='test'), + topic: str=REQ(default='Flock notifications')) -> HttpResponse: + + if len(payload["text"]) != 0: + message_body = payload["text"] + else: + message_body = payload["notification"] + body = u"{}".format(message_body) + + check_send_stream_message(user_profile, request.client, stream, topic, body) + + return json_success()