Commit Graph

1384 Commits

Author SHA1 Message Date
Alya Abbott
61db2bc158 integrations: Update GitHub intergation for new configuration UI. 2025-02-28 13:04:42 -08:00
Aditya Kumar Kasaudhan
18d83534ff github: Include old issue number in transfer message for new repo.
This commit updates the GitHub webhook integration to include the
old issue number in the transfer message sent for the new repository,
alongside the old repository's full name.
2025-02-27 09:22:15 -08:00
Anders Kaseorg
d7556b4060 requirements: Migrate to uv.
https://docs.astral.sh/uv/

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-02-24 22:29:24 -08:00
Aditya Kumar Kasaudhan
9d08063208 webhooks/github: Added support for issue transferred events.
On transferring an issue to another repository, GitHub sends
- a "transferred" event to the old repository's webhook URL,
- and an "opened event", containing links to the old issue,
  to the new repository's webhook URL.

This commit adds support for both events independently.
Fixes: #33450.
2025-02-21 15:34:14 -08:00
Anders Kaseorg
778a45d41e slack_incoming: Fix slack_error_handler typing.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-02-18 22:04:43 -08:00
Alex Vandiver
a7d513e5ec users: Remove unnecessary get_api_key helper.
Using the column name is clearer.
2025-02-13 12:40:53 -08:00
Niloth P
51839a72b9 HomeAssistant: Convert image instructions to code blocks.
Renamed the example screenshot to default image name as well.
2025-02-01 15:38:46 -08:00
Niloth P
fa0ea2aa2d webhooks: Remove second example screenshot from Sentry and Teamcity. 2025-02-01 15:38:46 -08:00
Niloth P
74d730f464 webhooks: Rename example screenshot images to match the default name.
The integrations - GoSquared, Greenhouse, OpsGenie and Zendesk - have
been using `000.png` as their example screenshots, renamed them to
match the default name `001.png`, to avoid passing them as arguments.
2025-02-01 15:38:46 -08:00
Niloth P
636f4f457c integration-docs: Remove context property recommended_channel_name.
The context property was previously being used in the macro
`git-webhook-url-with-branches` which has been removed as it is not in
use any longer.

The context property was now being used only in 2 integration docs, both
of which used it only in a single location, and directly used their own
names as the channel name. Making the context property unnecessary.
2025-01-30 11:59:38 -08:00
Alya Abbott
93dfd3dc1e integrations: Retitle Slack integration docs.
The updated titles are anti-pattern, but are much clearer.
2025-01-27 18:02:06 -08:00
PieterCK
e25da08886 integrations: Edit pass on Slack integration doc.
- Add a step to update the bot's API key if using a generic bot
for bidirectional bridging.
- Clarify setup options for how Slack channels are mapped.
- Edit for clarity and succinctness.
2025-01-27 18:02:06 -08:00
Mateusz Mandera
f81e514d07 slack: Fetch workspace users from /users.list in the correct manner.
1. Fetching from the `/users.list` endpoint is supposed to use
   pagination. Slack will return at most 1000 results in a single
   request. This means that our Slack import system hasn't worked
   properly for workspaces with more than 1000 users. Users after the
   first 1000 would be considered by our tool as mirror dummies and thus
   created with is_active=False,is_mirror_dummy=True.
   Ref https://api.slack.com/methods/users.list

2. Workspaces with a lot of users, and therefore requiring the use of
   paginated requests to fetch them all, might also get us to run into
   Slack's rate limits, since we'll be doing repeating requests to the
   endpoint.
   Therefore, the API fetch needs to also handle rate limiting errors
   correctly.
   Per, https://api.slack.com/apis/rate-limits#headers, we can just read
   the retry-after header from the rsponse and wait the indicated number
   of seconds before repeating the requests. This is an easy approach to
   implement, so that's what we go with here.
2025-01-24 16:41:53 -08:00
Anders Kaseorg
653b0b0436 ruff: Partially reformat Python with Ruff 0.9 (2025 style).
These are the changes that are backwards compatible with the 2024
style.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-01-14 09:42:16 -08:00
PieterCK
f89881d843 integrations: Change Slack private channel mention string.
In Slack webhook integration setup, the only scenario where a message
payload contains a channel mention without the channels name is when the
user mentions a private channel.
  e.g <#C07AVLQ3AUQ|>

This commit updates the string we use for such mention to "private Slack
channel" for better clarity.
2025-01-08 13:52:12 -05:00
PieterCK
059782bb9f integrations: Improve Slack integrations setup notification.
Previously, the notification message only informed users that the
integration URL was registered with Slack's Event API. However, it might
be misleading to send an "integration is successful" message when this
happens because we didn't verify that the token has the required scopes
or if the Slack token is even added to the URL at all.

Now that the integration also verifies the `slack_app_token`'s scope,
it's now more appropriate to send a notification message like
`get_setup_webhook_message` to let the user know that the setup is
indeed successful.
2025-01-08 13:52:12 -05:00
Niloth P
b7763f71e5 webhooks/opsgenie: Refactor to reduce redundancy in payload extraction. 2025-01-04 19:10:04 -08:00
Niloth P
ff96efbef4 webhooks/appveyor: Refactor to reduce redundancy in payload extraction.
Also renamed local functions to simpler names.
2025-01-04 19:10:04 -08:00
Niloth P
09f47d5a0a webhooks/github: Suppress "comment edited" events when body is same.
GitHub generates spurious edited events on hiding/unhiding a comment,
and on clicking "edit"/"update" without any changes, when the
comment "body" contains certain specific characters.

Instead of sending a notification message, we suppress those edge cases
by comparing the "body" content of the comment and changes in the event
payload.

Fixes #31042, #26136.
2025-01-03 15:18:39 -08:00
Niloth P
7261898d89 integrations: Remove Desk.com integration.
Desk.com has been discontinued by Salesforce in March 2020.
2024-12-31 16:31:48 -08:00
PieterCK
c6fd0ba424 integrations: Clean up duplicate functions.
This commit makes the Slack incoming webhook use the original
`convert_slack_formatting` and `convert_slack_workspace_mentions` from
`slack_message_conversion.py`. Previously those were not refactored out
into two smaller functions yet.

Fixes part of #30827.
2024-12-18 16:14:20 -08:00
PieterCK
a194d62093 integration-doc: Fix typo/wrong in Slack token scope list.
This commit deletes the duplicate `users:read` token scope from the list
of token scopes.
2024-12-18 16:14:20 -08:00
PieterCK
f2599bf33d integrations: Do check_token_access only initially.
Previously the `check_token_access` is called for every request we get
from Slack webhook, this may introduce significant latency.

This commit moves `check_token_access` to the same condition for when we
need to handle Slack challenge handshake so that we only do API token
check once per URL registered.

Additionally, we now check for the specific scopes that we need to run
the Slack webhook integration (SLACK_INTEGRATION_TOKEN_SCOPES).

Fixes part of #30827.
2024-12-18 16:14:19 -08:00
PieterCK
a746be807f slack_import: Make check_token_access more flexible.
Previously, the `check_token_access` function had a hardcoded
`required_parameters` variable because it was only used in the Slack
data importer. This commit refactors `required_parameters` into a
function parameter, enabling the function to check a Slack token’s scope
for other purposes, such as Slack webhook integration.

Additionally, this commit changes the Slack API call in
`check_token_access` from `teams.info` to `api.test`. The endpoint is
better suited for this purpose since we're only checking a token’s scope
using the response header here.
2024-12-18 16:11:31 -08:00
Niloth P
0d14ae1acf integration-docs: Remove the second screenshot from CircleCI doc.
The file had already been deleted, leaving behind its entry in the doc.
2024-12-12 15:04:02 -08:00
PieterCK
82e0468071 slack-integration: Update Slack integration documentation.
The doc now shows instructions to setup the integration using
Slack's Events API instead of the legacy Outgoing webhook
service.

Co-authored-by: Alya Abbott <alya@zulip.com>
Co-authored-by: Lauryn Menard <lauryn@zulip.com>
2024-12-11 13:06:52 -08:00
PieterCK
42a22e6aaa slack-integration: Block requests from Slack retries.
A Slack fail condition occurs when we don't respond with HTTP 200 within
3 seconds after Slack calls our endpoint. If this happens, Slack will
retry sending the same payload. This is often triggered because we need
to perform callbacks when converting messages. To avoid sending the same
message multiple times, we block subsequent retry calls from Slack.

This commit returns early HTTP 200 response as soon as we get any retry
calls from Slack.

Part of #30465.
2024-12-11 13:06:52 -08:00
PieterCK
c54d90e5c7 slack-integration: Add callback function to Slack API.
Payloads from Slack's Events API don't include human-readbale
information for a Slack username and for Slack channels.

This commit makes the Slack integration callback to the relevant
Slack API endpoints for that information.

Fixes #30074.
2024-12-11 13:06:52 -08:00
PieterCK
1ebbe2fd99 slack-integration: Add test fixtures for extra Slack payloads.
This commit adds 4 new payload fixtures to the Slack
integration for messages we don't process properly yet:

- Messages with code blocks.
- Messages with overlapping text formatting (e.g, bold
  and italic).
- Messages with formatted mentions.
- Messages with quote blocks.

The follow-up plan to add support for these kind of
Slack messages is tracked in #30827.

Part of #30465.
2024-12-11 13:06:52 -08:00
PieterCK
f29312ce03 slack-integration: Update Slack integration to handle Events API.
This updates the Slack webhook integration to handle the Slack Events
API[1], while maintaining backwards compatibility with Slack's legacy
Outgoing Webhook service.

The Events API introduces the "challenge" handshake[2] to verify and
add a new webhook URL for them to call. This commit adds a handler for
the challenge handshake.

Additionally, this commit reformats incoming payloads using the Slack
text reformatter from `slack_message_conversion.py`. There is some
duplicative code here because of the difference in Slack export data
and Slack's webhook payload.

Part of #30465

[1]: https://api.slack.com/apis/events-api#using-events-api
[2]: https://api.slack.com/apis/events-api#handshake
2024-12-11 13:06:52 -08:00
Niloth P
e731fb9eba integrations: Fix Jotform integration by accepting form-data payloads.
This does not add support for files.

Fixes part of #32460.

Co-authored by: PieterCK <pieterceka123@gmail.com>
2024-12-02 18:08:58 -08:00
Niloth P
f99e1a5dba integrations: Improve message formatting for Jotform. 2024-12-02 18:08:58 -08:00
Niloth P
d6fe41878e integrations: Fix $ position in Beeminder message template. 2024-11-26 12:43:31 -08:00
Niloth P
619ada36ed integrations: Refine Mention example screenshot. 2024-11-21 11:09:40 -08:00
Niloth P
5de2a7115c integrations: Refine Gitea example screenshot. 2024-11-21 11:09:40 -08:00
Niloth P
e1f256c905 integrations: Refine Basecamp example screenshot. 2024-11-21 11:09:40 -08:00
Niloth P
8e17ef3507 integrations: Refine CircleCI example screenshots.
- Removed the extra screenshot.
- Updated the fixture used to generate the screenshot to use a more
suitable topic name and commit message description.
2024-11-21 11:09:40 -08:00
Niloth P
8582e78f02 integrations: Refine Front example screenshot. 2024-11-21 11:09:40 -08:00
oscar
9d1ca5476a integration-docs: Remove create channel for generate webhook URL docs.
Updates text of generate-webhook-url-basic.md to replace the use of
the "Create the channel" step.

Removes {!create-channel.md!} from all the integrations docs that
also include {!generate-webhook-url-basic.md!}.

Fixes #32269.
2024-11-19 13:02:01 -08:00
Anders Kaseorg
c48ef926e1 mypy: Add types-defusedxml.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-11-19 11:09:34 -08:00
David Flanagan
eec9b8e683 integrations: Avoid UUIDs in topics for linear.
The initial implementation for this feature used the issue UUID
to create the topics, as some of the webhook events only provide
this and it is the only way to group sub-issues with parents.

However, if we sacrifice this and allow sub-issues to be
their own topic then we can avoid using the UUID as the topic name.

I think the quality of life improvement to topics here warrants this change,
as UUID topic names can be come unruly very quickly.

Part of #23118.
2024-11-15 11:06:39 -08:00
Giovanni Silva
70d559cafa integrations: Update New Relic integration.
Newrelic has introduced a new update. This commit
updates the exisiting integration by adding support
for new types of payloads and cleaning up legacy
codes and fixtures.

Fixes #29729.

Co-authored-by: Pieter CK <pieterceka123@gmail.com>
Co-authored-by: Lauryn Menard <lauryn@zulip.com>
2024-11-08 15:49:56 -08:00
PieterCK
92437b4ab5 integrations: Refactor slack_incoming webhook.
This commit refactors `render_attachment` and `render_block`
out of slack_incoming.py to promote reusability.

The primary motivation for this refactor is to add support for
converting integration bots messages in Slack exports, which could use
the same functions.

Part of #31311.
2024-11-07 10:47:08 -08:00
swayam0322
6c583c9bfe integrations: Update GoCD integration.
Previously, the GoCD integration relied on GoCD's integration with bug
tracking and monitoring tools through the users' Config XML file [1].
However, this feature no longer works as expected, as it cannot send
HTTPS payloads to an external endpoint.

This commit updates our GoCD integration to use Sentry's WebHook
notifier GoCD plugin [2] to send webhook payloads from users GoCD server
to Zulip. We are using an older version of the plugin—v0.0.6—because the
newer version—v0.0.9—doesn't work at this time.

Additionally, this change reformats the notifications to include more
details on the GoCD event, such as lists of passed and failed jobs.

Fixes #21224.

Co-authored-by: Pieter CK <pieterceka123@gmail.com>

[1]:
https://docs.gocd.org/current/integration/#integration-with-bug-tracking-and-story-management-tools
[2]:
https://github.com/getsentry/gocd-webhook-notification-plugin/releases/tag/v0.0.6
2024-11-07 10:25:29 -08:00
aniebietafia
257ce8bca2 integrations: Create incoming webhook for Airbyte.
Note about the documentation: There are currently two "Save changes"
buttons on the Airbyte "Notifications" settings page, so the
instructions specify which one to use for clarity.
2024-11-01 10:04:48 -07:00
Aditya Kumar Kasaudhan
d1ff871523 webhooks: Support filtering GitHub activity from private repositories.
Currently, the GitHub webhook sends activity from both public and private
repositories, which could lead to unintended disclosure of sensitive
information from private repositories.

This commit introduces a ignore_private_repositories parameter to the
webhook URL. When set to true, the webhook ignore processing activity from
private repositories, ensuring that such activities are not posted to
Zulip streams. By default, if the parameter is omitted or set to false,
activities from both public and private repositories are processed
normally. This provides users with the flexibility to control the
visibility of private repository activities without altering the default
behavior.

More importantly, this introduces a cleaner mechanism for individual
incoming webhooks to declare support for settings not common to all
webhook integrations.

Fixes #31638.
2024-10-31 10:40:28 -07:00
Aditya Kumar Kasaudhan
d448b75176 slack_incoming: Add ok=false to JSON in case of error.
Previously, errors were returned using Zulip's default format,
which did not match Slack's expected response structure.

This change ensures that errors in the Slack incoming webhook handler
return JSON responses in Slack's expected format: {ok: false, error:
"error string"}.

Fixes: #31878.
2024-10-30 15:33:29 -07:00
Niloth P
bd83dbfb42 git webhooks: Handle assignment events better.
With the introduction of `assignee_updated` parameter in the library,
- Github, Gitea, Gogs can display the assignee in assignment events.
- Github can display the user unassigned in unassignment events.

Fixes https://chat.zulip.org/#narrow/channel/127-integrations/near/1965136
2024-10-24 12:46:39 -07:00
Lauryn Menard
240c4d85ae docs: Update existing links to use "channel" operator. 2024-10-11 17:00:23 -07:00
Pierre Carru
5cbe3203f5 slack_incoming: add ok=true to json in case of success.
This better simulates the Slack API, which is important, since some
integrations check this response and decide whether the Slack endpoint
is working based on what they receive.
2024-10-04 08:42:27 -07:00