mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
integrations: Add basic open collective integration.
Add basic open collective integration for the user donation event. Fixes #18319
This commit is contained in:
committed by
Tim Abbott
parent
e94b6afb00
commit
2b70e88fda
BIN
static/images/integrations/bot_avatars/opencollective.png
Normal file
BIN
static/images/integrations/bot_avatars/opencollective.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
1
static/images/integrations/logos/opencollective.svg
Normal file
1
static/images/integrations/logos/opencollective.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" style="enable-background:new 0 0 32 32" xml:space="preserve"><path d="M29.1 6.9c3.8 5.5 3.8 12.7 0 18.2L25 21c1.7-3.1 1.7-6.9 0-9.9l4.1-4.2zm-4-4L21 7c-3.2-1.7-7.1-1.7-10.2.2-3.1 1.8-5 5.2-5 8.8 0 3.6 1.9 7 5 8.8s7 1.9 10.2.2l4.1 4.1c-4.9 3.4-11.3 3.8-16.5 1S0 21.9 0 16C0 10 3.3 4.6 8.6 1.8 13.8-.9 20.2-.5 25.1 2.9zm4 4c3.8 5.5 3.8 12.7 0 18.2L25 21c1.7-3.1 1.7-6.9 0-9.9l4.1-4.2z"/></svg>
|
||||
|
After Width: | Height: | Size: 451 B |
BIN
static/images/integrations/opencollective/001.png
Normal file
BIN
static/images/integrations/opencollective/001.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
@@ -423,6 +423,9 @@ WEBHOOK_INTEGRATIONS: List[WebhookIntegration] = [
|
||||
stream_name="opbeat",
|
||||
function="zerver.webhooks.opbeat.view.api_opbeat_webhook",
|
||||
),
|
||||
WebhookIntegration(
|
||||
"opencollective", ["communication"], display_name="Open Collective Incoming Webhook"
|
||||
),
|
||||
WebhookIntegration("opsgenie", ["meta-integration", "monitoring"]),
|
||||
WebhookIntegration("pagerduty", ["monitoring"], display_name="PagerDuty"),
|
||||
WebhookIntegration("papertrail", ["monitoring"]),
|
||||
@@ -761,6 +764,7 @@ DOC_SCREENSHOT_CONFIG: Dict[str, List[BaseScreenshotConfig]] = {
|
||||
ScreenshotConfig("incident_closed.json", "003.png"),
|
||||
],
|
||||
"opbeat": [ScreenshotConfig("error_reopen.json")],
|
||||
"opencollective": [ScreenshotConfig("one_time_donation.json")],
|
||||
"opsgenie": [ScreenshotConfig("addrecipient.json", image_name="000.png")],
|
||||
"pagerduty": [ScreenshotConfig("trigger_v2.json")],
|
||||
"papertrail": [ScreenshotConfig("short_post.json", payload_as_query_param=True)],
|
||||
|
||||
0
zerver/webhooks/opencollective/__init__.py
Normal file
0
zerver/webhooks/opencollective/__init__.py
Normal file
17
zerver/webhooks/opencollective/doc.md
Normal file
17
zerver/webhooks/opencollective/doc.md
Normal file
@@ -0,0 +1,17 @@
|
||||
This integration currently supports getting notifications to a stream of your Zulip instance,
|
||||
when a new member signs-up on an **Open Collective** page.
|
||||
|
||||
1. {!create-stream.md!}
|
||||
|
||||
1. {!create-bot-construct-url-indented.md!}
|
||||
|
||||
1. Go to [Open Collective Website](https://opencollective.com/), find
|
||||
your desired collective page, then go to *Settings* -> *Webhooks*, paste the
|
||||
bot URL and choose *Activity* -> *New Member*.
|
||||
|
||||
{!congrats.md!}
|
||||
|
||||

|
||||
|
||||
In the future, this integration can be developed in order to
|
||||
support other types of *Activity* such as *New Transaction*, *Subscription Canceled* etc.
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"createdAt": "2021-06-21T17:25:24.344Z",
|
||||
"id": 1242511,
|
||||
"type": "collective.member.created",
|
||||
"CollectiveId": 281290,
|
||||
"data": {
|
||||
"member": {
|
||||
"role": "BACKER",
|
||||
"description": null,
|
||||
"since": "2021-06-21T17:25:24.332Z",
|
||||
"memberCollective": {
|
||||
"id": 280138,
|
||||
"type": "USER",
|
||||
"slug": "leyteris-kyriazanos",
|
||||
"name": "Λευτέρης Κυριαζάνος",
|
||||
"company": null,
|
||||
"website": null,
|
||||
"twitterHandle": null,
|
||||
"githubHandle": null,
|
||||
"description": null,
|
||||
"previewImage": null
|
||||
}
|
||||
},
|
||||
"order": {
|
||||
"id": 183773,
|
||||
"totalAmount": 100,
|
||||
"currency": "EUR",
|
||||
"description": "Financial contribution to Test-Webhooks",
|
||||
"interval": null,
|
||||
"createdAt": "2021-06-21T17:25:17.968Z",
|
||||
"quantity": 1,
|
||||
"formattedAmount": "€1.00",
|
||||
"formattedAmountWithInterval": "€1.00"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"createdAt": "2021-04-30T19:20:04.346Z",
|
||||
"id": 1121199,
|
||||
"type": "collective.member.created",
|
||||
"CollectiveId": 30312,
|
||||
"data": {
|
||||
"member": {
|
||||
"role": "BACKER",
|
||||
"description": null,
|
||||
"since": "2021-04-30T19:20:04.314Z",
|
||||
"memberCollective": {
|
||||
"type": "USER",
|
||||
"name": "Incognito",
|
||||
"previewImage": null
|
||||
}
|
||||
},
|
||||
"order": {
|
||||
"id": 168629,
|
||||
"totalAmount": 100,
|
||||
"currency": "USD",
|
||||
"description": "Monthly financial contribution to Zulip",
|
||||
"interval": "month",
|
||||
"createdAt": "2021-04-30T19:19:58.647Z",
|
||||
"quantity": 1,
|
||||
"formattedAmount": "$1.00",
|
||||
"formattedAmountWithInterval": "$1.00 / month"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
31
zerver/webhooks/opencollective/tests.py
Normal file
31
zerver/webhooks/opencollective/tests.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
|
||||
class OpenCollectiveHookTests(WebhookTestCase):
|
||||
STREAM_NAME = "test"
|
||||
URL_TEMPLATE = "/api/v1/external/opencollective?&api_key={api_key}&stream={stream}"
|
||||
WEBHOOK_DIR_NAME = "opencollective"
|
||||
|
||||
# Note: Include a test function per each distinct message condition your integration supports
|
||||
def test_one_time_donation(self) -> None: # test one time donation
|
||||
expected_topic = "New Member"
|
||||
expected_message = "@_**Λευτέρης Κυριαζάνος** donated **€1.00**! :tada:"
|
||||
|
||||
self.check_webhook(
|
||||
"one_time_donation",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
content_type="application/x-www-form-urlencoded",
|
||||
)
|
||||
|
||||
def test_one_time_incognito_donation(self) -> None: # test one time incognito donation
|
||||
expected_topic = "New Member"
|
||||
expected_message = "An **Incognito** member donated **$1.00**! :tada:"
|
||||
|
||||
# use fixture named helloworld_hello
|
||||
self.check_webhook(
|
||||
"one_time_incognito_donation",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
content_type="application/x-www-form-urlencoded",
|
||||
)
|
||||
47
zerver/webhooks/opencollective/view.py
Normal file
47
zerver/webhooks/opencollective/view.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import webhook_view
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
from zerver.models import UserProfile
|
||||
|
||||
MEMBER_NAME_TEMPLATE = "{name}"
|
||||
AMOUNT_TEMPLATE = "{amount}"
|
||||
|
||||
|
||||
@webhook_view("OpenCollective")
|
||||
@has_request_variables
|
||||
def api_opencollective_webhook(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
payload: Dict[str, Any] = REQ(argument_type="body"),
|
||||
) -> HttpResponse:
|
||||
|
||||
name = get_name(payload)
|
||||
amount = get_amount(payload)
|
||||
|
||||
# construct the body of the message
|
||||
body = ""
|
||||
|
||||
if name == "Incognito": # Incognito donation
|
||||
body = f"An **Incognito** member donated **{amount}**! :tada:"
|
||||
else: # non - Incognito donation
|
||||
body = f"@_**{name}** donated **{amount}**! :tada:"
|
||||
|
||||
topic = "New Member"
|
||||
|
||||
# send the message
|
||||
check_send_webhook_message(request, user_profile, topic, body)
|
||||
|
||||
return json_success()
|
||||
|
||||
|
||||
def get_name(payload: Dict[str, Any]) -> str:
|
||||
return MEMBER_NAME_TEMPLATE.format(name=payload["data"]["member"]["memberCollective"]["name"])
|
||||
|
||||
|
||||
def get_amount(payload: Dict[str, Any]) -> str:
|
||||
return AMOUNT_TEMPLATE.format(amount=payload["data"]["order"]["formattedAmount"])
|
||||
Reference in New Issue
Block a user