Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

integrations: Add backend for Webex video call integration.

apoorvapendsed9631d763dab
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 0d373ba8d3e..fe4068a763a 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,19 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 12.0
+**Feature level 493**
+
+* [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events),
+ `PATCH /realm`: Webex OAuth integration added as an option
+ for the realm setting `video_chat_provider`.
+* [`POST /calls/webex/create`](/api/create-webex-video-call): Added
+ a new endpoint to create a Webex video call URL.
+* [`POST /register`](/api/register-queue): Added `has_webex_token`
+ boolean field to response.
+* [`GET /events`](/api/get-events): A `has_webex_token` event is sent
+ to clients when the user has completed the OAuth flow for the Webex
+ video call integration.
+
**Feature level 492**
* [`POST /users/me/api_key/regenerate`](/api/regenerate-api-key): When
diff --git a/api_docs/include/rest-endpoints.md b/api_docs/include/rest-endpoints.md
index ec7934a07ad..073cf4ceb21 100644
--- a/api_docs/include/rest-endpoints.md
+++ b/api_docs/include/rest-endpoints.md
@@ -186,4 +186,5 @@
* [Create BigBlueButton video call](/api/create-big-blue-button-video-call)
* [Create Constructor Groups video call](/api/create-constructor-groups-video-call)
* [Create Nextcloud Talk video call](/api/create-nextcloud-talk-video-call)
+* [Create Webex video call](/api/create-webex-video-call)
* [Outgoing webhook payloads](/api/outgoing-webhook-payload)
diff --git a/version.py b/version.py
index 84b25e30efd..420735b5aff 100644
--- a/version.py
+++ b/version.py
@@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# https://zulip.readthedocs.io/en/latest/documentation/api.html#step-by-step-guide
# Also available at docs/documentation/api.md.
-API_FEATURE_LEVEL = 492
+API_FEATURE_LEVEL = 493
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index e81c9322453..a039c362254 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -37,6 +37,7 @@ from zerver.lib.event_types import (
EventDraftsAdd,
EventDraftsRemove,
EventDraftsUpdate,
+ EventHasWebexToken,
EventHasZoomToken,
EventHeartbeat,
EventInvitesChanged,
@@ -256,6 +257,7 @@ check_web_reload_client_event = make_checker(EventWebReloadClient)
_check_channel_folder_update = make_checker(EventChannelFolderUpdate)
_check_delete_message = make_checker(EventDeleteMessage)
_check_has_zoom_token = make_checker(EventHasZoomToken)
+_check_has_webex_token = make_checker(EventHasWebexToken)
_check_legacy_presence = make_checker(EventLegacyPresence)
_check_modern_presence = make_checker(EventModernPresence)
_check_muted_topics = make_checker(EventMutedTopics)
@@ -337,6 +339,15 @@ def check_has_zoom_token(
assert event["value"] == value
+def check_has_webex_token(
+ var_name: str,
+ event: dict[str, object],
+ value: bool,
+) -> None:
+ _check_has_webex_token(var_name, event)
+ assert event["value"] == value
+
+
def check_muted_topics(
var_name: str,
event: dict[str, object],
diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.py
index 3218ab9c416..789f3c5b540 100644
--- a/zerver/lib/event_types.py
+++ b/zerver/lib/event_types.py
@@ -224,6 +224,11 @@ class EventHasZoomToken(BaseEvent):
value: bool
+class EventHasWebexToken(BaseEvent):
+ type: Literal["has_webex_token"]
+ value: bool
+
+
class EventHeartbeat(BaseEvent):
type: Literal["heartbeat"]
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index 97b63189e49..2bd3b4fab45 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -942,6 +942,7 @@ def fetch_initial_state_data(
if want("video_calls"):
state["has_zoom_token"] = settings_user.third_party_api_state.get("zoom") is not None
+ state["has_webex_token"] = settings_user.third_party_api_state.get("webex") is not None
if want("giphy"):
# Normally, it would be a nasty security bug to send a
@@ -2012,6 +2013,8 @@ def apply_event(
raise AssertionError("Unexpected event type {type}/{op}".format(**event))
elif event["type"] == "has_zoom_token":
state["has_zoom_token"] = event["value"]
+ elif event["type"] == "has_webex_token":
+ state["has_webex_token"] = event["value"]
elif event["type"] == "web_reload_client":
# This is an unlikely race, where the queue was created with a
# previous Tornado process, which restarted, and subsequently
diff --git a/zerver/models/realms.py b/zerver/models/realms.py
index d161cb08089..0f7b9880b51 100644
--- a/zerver/models/realms.py
+++ b/zerver/models/realms.py
@@ -676,6 +676,10 @@ class Realm(models.Model):
"name": "Nextcloud Talk",
"id": 7,
},
+ "webex": {
+ "name": "Webex",
+ "id": 8,
+ },
}
video_chat_provider = models.PositiveSmallIntegerField(
@@ -1119,6 +1123,10 @@ class Realm(models.Model):
or settings.NEXTCLOUD_TALK_PASSWORD is None
):
continue
+ if provider == "webex" and (
+ settings.VIDEO_WEBEX_CLIENT_ID is None or settings.VIDEO_WEBEX_CLIENT_SECRET is None
+ ):
+ continue
enabled_video_chat_providers[provider] = self.VIDEO_CHAT_PROVIDERS[provider]
return enabled_video_chat_providers
diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.py
index 6909b51ea76..f6a3aae6dd5 100644
--- a/zerver/openapi/test_curl_examples.py
+++ b/zerver/openapi/test_curl_examples.py
@@ -35,10 +35,11 @@ UNTESTED_GENERATED_CURL_EXAMPLES = {
# Having a message for a specific user available to test this endpoint
# is tricky for testing.
"delete-reminder",
- # Would need Constructor Groups credentials configured to test this endpoint.
+ # Video call endpoints that need the third-party call provider
+ # to be configured to test the curl example for the endpoint.
"create-constructor-groups-video-call",
- # Would need Nextcloud Talk server configured to test this endpoint.
"create-nextcloud-talk-video-call",
+ "create-webex-video-call",
}
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 4f14032e818..c8b4d471021 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -1203,6 +1203,31 @@ paths:
"value": true,
"id": 0,
}
+ - type: object
+ description: |
+ Event sent to a user's clients when the user completes the OAuth flow for
+ the [Webex integration](/help/configure-call-provider). Clients need to
+ know whether initiating Webex OAuth flow is required before creating a
+ Webex call.
+ properties:
+ id:
+ $ref: "#/components/schemas/EventIdSchema"
+ type:
+ allOf:
+ - $ref: "#/components/schemas/EventTypeSchema"
+ - enum:
+ - has_webex_token
+ value:
+ type: boolean
+ description: |
+ A boolean specifying whether the user has a Webex access token.
+ additionalProperties: false
+ example:
+ {
+ "type": "has_webex_token",
+ "value": true,
+ "id": 0,
+ }
- type: object
description: |
A simple event sent when the set of invitations changes.
@@ -5969,11 +5994,15 @@ paths:
- 5 = Zoom (Server to Server OAuth integration)
- 6 = Constructor Groups
- 7 = Nextcloud Talk
+ - 8 = Webex (User OAuth integration)
Note that only one of the [Zoom integrations][zoom-video-calls] can
be configured on a Zulip server.
- **Changes**: In Zulip 12.0 (feature level 465), added the
+ **Changes**: In Zulip 12.0 (feature level 493),
+ added the Webex OAuth option.
+
+ In Zulip 12.0 (feature level 465), added the
Constructor Groups option.
In Zulip 12.0 (feature level 460), added the
@@ -19567,6 +19596,17 @@ paths:
completed OAuth flow for the [Zoom integration](/help/configure-call-provider).
Clients need to know whether initiating Zoom OAuth is required before
creating a Zoom call.
+ has_webex_token:
+ type: boolean
+ description: |
+ Present if `video_calls` is present in `fetch_event_types`.
+
+ A boolean that denotes whether the user has completed the OAuth flow for
+ the [Webex integration](/help/configure-call-provider). Clients need to
+ know whether initiating Webex OAuth flow is required before creating a
+ Webex call.
+
+ **Changes**: New in Zulip 12.0 (feature level 493).
giphy_api_key:
type: string
description: |
@@ -20399,11 +20439,15 @@ paths:
- 5 = Zoom (Server to Server OAuth integration)
- 6 = Constructor Groups
- 7 = Nextcloud Talk
+ - 8 = Webex (User OAuth integration)
Note that only one of the [Zoom integrations][zoom-video-calls] can
be configured on a Zulip server.
- **Changes**: In Zulip 12.0 (feature level 465), added the
+ **Changes**: In Zulip 12.0 (feature level 493), added the
+ Webex OAuth option.
+
+ In Zulip 12.0 (feature level 465), added the
Nextcloud Talk option.
In Zulip 12.0 (feature level 460), added the
@@ -26686,6 +26730,48 @@ paths:
"url": "https://nextcloud.example.com/index.php/call/abc123xyz",
}
+ /calls/webex/create:
+ post:
+ tags: ["channels"]
+ operationId: create-webex-video-call
+ summary: Create Webex video call
+ description: |
+ Create a video call URL for a Webex video call.
+
+ Requires [Webex integration](/integrations/webex) to be configured
+ on the Zulip server.
+
+ Clients should confirm that the user has completed the OAuth process
+ with Webex and has a Webex token before attempting to create a video
+ call URL. See the `has_webex_token` field in the [`POST /register`
+ response](/api/register-queue), as well as the [`has_webex_token`
+ event type](/api/get-events#has_webex_token).
+
+ **Changes**: New in Zulip 12.0 (feature level 493).
+ responses:
+ "200":
+ description: Success.
+ content:
+ application/json:
+ schema:
+ allOf:
+ - $ref: "#/components/schemas/JsonSuccessBase"
+ - additionalProperties: false
+ properties:
+ result: {}
+ msg: {}
+ ignored_parameters_unsupported: {}
+ url:
+ description: |
+ The URL for the Webex meeting.
+ type: string
+ example: "https://xxkk-7xpz.webex.com/xxkk-7xpz/j.php?MTID=mebb3ba1f366f683bcaec9d32773ce034"
+ example:
+ {
+ "msg": "",
+ "result": "success",
+ "url": "https://xxkk-7xpz.webex.com/xxkk-7xpz/j.php?MTID=mebb3ba1f366f683bcaec9d32773ce034",
+ }
/calls/constructorgroups/create:
post:
tags: ["channels"]
diff --git a/zerver/signals.py b/zerver/signals.py
index 5ee62ec4458..0bce38d58c0 100644
--- a/zerver/signals.py
+++ b/zerver/signals.py
@@ -96,11 +96,14 @@ def email_on_new_login(sender: Any, user: UserProfile, request: Any, **kwargs: A
@receiver(user_logged_out)
-def clear_zoom_token_on_logout(
+def clear_call_tokens_on_logout(
sender: object, *, user: UserProfile | None, **kwargs: object
) -> None:
# Loaded lazily so django.setup() succeeds before static asset generation
from zerver.actions.video_calls import do_set_video_call_provider_token
- if user is not None and user.third_party_api_state.get("zoom") is not None:
- do_set_video_call_provider_token(user, "zoom", None)
+ if user is not None:
+ if user.third_party_api_state.get("zoom") is not None:
+ do_set_video_call_provider_token(user, "zoom", None)
+ if user.third_party_api_state.get("webex") is not None:
+ do_set_video_call_provider_token(user, "webex", None)
diff --git a/zerver/tests/test_create_video_call.py b/zerver/tests/test_create_video_call.py
index 1283701caad..e45c674c445 100644
--- a/zerver/tests/test_create_video_call.py
+++ b/zerver/tests/test_create_video_call.py
@@ -224,6 +224,154 @@ class ZoomVideoCallTestUserAuth(ZulipTestCase):
self.assert_json_success(response)
+class WebexVideoCallTestOAuth(ZulipTestCase):
+ @override
+ def setUp(self) -> None:
+ super().setUp()
+ self.user = self.example_user("hamlet")
+ self.login_user(self.user)
+
+ def test_register_webex_request_no_settings(self) -> None:
+ with self.settings(VIDEO_WEBEX_CLIENT_ID=None):
+ response = self.client_get("/calls/webex/register")
+ self.assert_json_error(
+ response,
+ "Webex credentials have not been configured",
+ )
+
+ def test_register_webex_request(self) -> None:
+ response = self.client_get("/calls/webex/register")
+ self.assertEqual(response.status_code, 302)
+ self.assertTrue(response["Location"].startswith("https://webexapis.com/v1/authorize"))
+
+ @responses.activate
+ def test_create_webex_access_token(self) -> None:
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/access_token",
+ json={"access_token": "oldtoken", "expires_in": -60},
+ )
+
+ response = self.client_get(
+ "/calls/webex/complete",
+ {"code": "code", "state": '{"realm":"zulip","sid":""}'},
+ )
+ self.assertEqual(response.status_code, 200)
+
+ @responses.activate
+ def test_create_webex_adhoc_meeting(self) -> None:
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/access_token",
+ json={"access_token": "token", "expires_in": 3600},
+ )
+
+ response = self.client_get(
+ "/calls/webex/complete",
+ {"code": "code", "state": '{"realm":"zulip","sid":""}'},
+ )
+ self.assertEqual(response.status_code, 200)
+
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/rooms",
+ json={"id": "room_id_123"},
+ status=200,
+ )
+
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/meetings",
+ json={
+ "id": "meeting_id_456",
+ "webLink": "https://webex.com/test",
+ },
+ status=200,
+ )
+
+ response = self.client_post("/json/calls/webex/create")
+
+ result = self.assert_json_success(response)
+ self.assertEqual(result["url"], "https://webex.com/test")
+
+ # Test for token removal on logout.
+ self.logout()
+ self.login_user(self.user)
+
+ response = self.client_post("/json/calls/webex/create")
+ self.assert_json_error(response, "Invalid Webex access token")
+
+ @responses.activate
+ def test_create_webex_personal_room_meeting(self) -> None:
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/access_token",
+ json={"access_token": "token", "expires_in": 3600},
+ )
+
+ self.client_get(
+ "/calls/webex/complete",
+ {"code": "code", "state": '{"realm":"zulip","sid":""}'},
+ )
+
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/rooms",
+ status=403,
+ )
+
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/meetings",
+ json={
+ "id": "meeting_id_456",
+ "webLink": "https://webex.com/test",
+ },
+ status=200,
+ )
+
+ result = self.client_post("/json/calls/webex/create")
+
+ assert responses.calls[-1].request.body is not None
+ payload = orjson.loads(responses.calls[-1].request.body)
+ self.assertEqual(payload["scheduledType"], "personalRoomMeeting")
+
+ json = self.assert_json_success(result)
+ self.assertEqual(json["url"], "https://webex.com/test")
+
+ def test_create_webex_realm_redirect(self) -> None:
+ response = self.client_get(
+ "/calls/webex/complete",
+ {"code": "code", "state": '{"realm":"lear","sid":"somesid"}'},
+ )
+ self.assertEqual(response.status_code, 302)
+ self.assertIn("http://lear.testserver/", response["Location"])
+ self.assertIn("somesid", response["Location"])
+
+ @responses.activate
+ def test_webex_public_room_creation_failure(self) -> None:
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/access_token",
+ json={"access_token": "token", "expires_in": 3600},
+ )
+
+ self.client_get(
+ "/calls/webex/complete",
+ {"code": "code", "state": '{"realm":"zulip","sid":""}'},
+ )
+
+ responses.add(
+ responses.POST,
+ "https://webexapis.com/v1/rooms",
+ status=500,
+ )
+
+ response = self.client_post("/json/calls/webex/create")
+
+ self.assert_json_error(response, "Failed to create Webex public room.")
+
+
class ZoomVideoCallTestServerAuth(ZulipTestCase):
@override
def setUp(self) -> None:
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 0c92a78e93f..170ddcfd187 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -184,6 +184,7 @@ from zerver.lib.event_schema import (
check_draft_add,
check_draft_remove,
check_draft_update,
+ check_has_webex_token,
check_has_zoom_token,
check_heartbeat,
check_invites_changed,
@@ -4400,6 +4401,15 @@ class NormalActionsTest(BaseAction):
do_set_video_call_provider_token(self.user_profile, "zoom", None)
check_has_zoom_token("events[0]", events[0], value=False)
+ def test_has_webex_token(self) -> None:
+ with self.verify_action() as events:
+ do_set_video_call_provider_token(self.user_profile, "webex", {"access_token": "token"})
+ check_has_webex_token("events[0]", events[0], value=True)
+
+ with self.verify_action() as events:
+ do_set_video_call_provider_token(self.user_profile, "webex", None)
+ check_has_webex_token("events[0]", events[0], value=False)
+
def test_restart_event(self) -> None:
with self.verify_action(num_events=1, state_change_expected=False):
send_restart_events()
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index 8f430eba573..8d42700456c 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -98,6 +98,7 @@ class HomeTest(ZulipTestCase):
"gif_rating_policy_options",
"has_zoom_token",
"idle_queue_timeout_secs",
+ "has_webex_token",
"is_admin",
"is_guest",
"is_moderator",
diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py
index cabcb40576a..745417dbd3d 100644
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -1365,6 +1365,24 @@ class RealmTest(ZulipTestCase):
nextcloud_talk_provider_id,
)
+ webex_provider_id = Realm.VIDEO_CHAT_PROVIDERS["webex"]["id"]
+ req = {"video_chat_provider": f"{webex_provider_id}"}
+
+ with self.settings(VIDEO_WEBEX_CLIENT_ID=None):
+ result = self.client_patch("/json/realm", req)
+ self.assert_json_error(result, f"Invalid video_chat_provider {webex_provider_id}")
+
+ with self.settings(VIDEO_WEBEX_CLIENT_SECRET=None):
+ result = self.client_patch("/json/realm", req)
+ self.assert_json_error(result, f"Invalid video_chat_provider {webex_provider_id}")
+
+ result = self.client_patch("/json/realm", req)
+ self.assert_json_success(result)
+ self.assertEqual(
+ get_realm("zulip").video_chat_provider,
+ webex_provider_id,
+ )
+
def test_data_deletion_schedule_when_deactivating_realm(self) -> None:
self.login("desdemona")
diff --git a/zerver/views/video_calls.py b/zerver/views/video_calls.py
index f7803bf1cd8..34fb4a6eec3 100644
--- a/zerver/views/video_calls.py
+++ b/zerver/views/video_calls.py
@@ -1,10 +1,11 @@
+import datetime
import hashlib
import json
import logging
import random
from abc import ABC, abstractmethod
from base64 import b64encode
-from typing import Any
+from typing import Any, Literal
from urllib.parse import quote, urlencode, urljoin, urlsplit
import requests
@@ -15,6 +16,7 @@ from django.http import HttpRequest, HttpResponse
from django.middleware import csrf
from django.shortcuts import redirect, render
from django.utils.crypto import constant_time_compare, salted_hmac
+from django.utils.timezone import now as timezone_now
from django.utils.translation import gettext as _
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
@@ -304,6 +306,54 @@ class OAuthVideoCallProvider(ABC):
return self.get_meeting_details(request, response)
+class WebexOAuthProvider(OAuthVideoCallProvider):
+ provider_name = "Webex"
+ token_key_name = "webex"
+
+ def __init__(self) -> None:
+ self.client_id = settings.VIDEO_WEBEX_CLIENT_ID
+ self.client_secret = settings.VIDEO_WEBEX_CLIENT_SECRET
+ self.authorization_url = urljoin(settings.VIDEO_WEBEX_API_URL, "authorize")
+ self.token_url = urljoin(settings.VIDEO_WEBEX_API_URL, "access_token")
+ self.auto_refresh_url = urljoin(settings.VIDEO_WEBEX_API_URL, "access_token")
+ self.create_meeting_url = urljoin(settings.VIDEO_WEBEX_API_URL, "meetings")
+ self.create_room_url = urljoin(settings.VIDEO_WEBEX_API_URL, "rooms")
+ # We need spark:all to create meetings with an associated roomId, which are
+ # ad-hoc meetings in our case: https://developer.webex.com/meeting/docs/meetings.
+ self.authorization_scope = "meeting:schedules_read meeting:schedules_write spark:all"
+
+ @override
+ def get_meeting_details(self, request: HttpRequest, response: Response) -> HttpResponse:
+ return json_success(request, data={"url": response.json()["webLink"]})
+
+ # For ad-hoc meetings, we need to create a public room as a prerequisite,
+ # where a public room is a room that lets anyone in the Webex organization
+ # join meetings associated with it. Note that the public room feature is
+ # restricted to paid Webex organizations.
+ def maybe_generate_public_room_id(self, user: UserProfile) -> str | None:
+ create_room_payload = {
+ "title": "Webex Zulip Meeting",
+ "isPublic": True,
+ "description": "A Webex meeting created via the Zulip client.",
+ }
+ response = self.oauth_post(user, self.create_room_url, json=create_room_payload)
+
+ # This is probably a free organization, because the Webex API sends a 403
+ # response when trying to create a public room with user credentials that
+ # belong to a free organization with the message: "Spaces belonging to a
+ # free org cannot be made public". For details, see error docs at
+ # https://developer.webex.com/messaging/docs/api/v1/rooms/create-a-room.
+ if response.status_code == 403:
+ return None
+ elif not response.ok:
+ raise JsonableError(
+ _("Failed to create {provider_name} public room.").format(
+ provider_name=self.provider_name
+ )
+ )
+ return response.json()["id"]
+
+
class ZoomGeneralOAuthProvider(OAuthVideoCallProvider):
provider_name = "Zoom"
authorization_scope = None
@@ -328,6 +378,12 @@ def register_zoom_user(request: HttpRequest) -> HttpResponse:
return ZoomGeneralOAuthProvider().register_user(request=request)
+@zulip_login_required
+@never_cache
+def register_webex_user(request: HttpRequest) -> HttpResponse:
+ return WebexOAuthProvider().register_user(request=request)
+
+
class StateDictRealm(TypedDict):
realm: str
sid: str
@@ -347,6 +403,19 @@ class ZoomPayload(TypedDict):
default_password: bool
+class WebexPersonalRoomMeetingPayload(TypedDict):
+ title: str
+ start: str
+ end: str
+ scheduledType: Literal["personalRoomMeeting"]
+
+
+class WebexAdhocMeetingPayload(TypedDict):
+ title: str
+ adhoc: Literal[True]
+ roomId: str
+
+
@never_cache
@zulip_login_required
@typed_endpoint
@@ -361,6 +430,20 @@ def complete_zoom_user(
return ZoomGeneralOAuthProvider().complete_user(request, code=code, sid=state["sid"])
+@never_cache
+@zulip_login_required
+@typed_endpoint
+def complete_webex_user(
+ request: HttpRequest,
+ *,
+ code: str,
+ state: Json[StateDictRealm],
+) -> HttpResponse:
+ if get_subdomain(request) != state["realm"]:
+ return redirect(urljoin(get_realm(state["realm"]).url, request.get_full_path()))
+ return WebexOAuthProvider().complete_user(request, code=code, sid=state["sid"])
+
+
@cache_with_key(zoom_server_access_token_cache_key, timeout=3600 - 240)
def get_zoom_server_to_server_access_token(account_id: str) -> str:
if settings.VIDEO_ZOOM_CLIENT_ID is None:
@@ -456,6 +539,36 @@ def make_zoom_video_call(
return ZoomGeneralOAuthProvider().make_video_call(request=request, user=user, payload=payload)
+@typed_endpoint_without_parameters
+def make_webex_video_call(request: HttpRequest, user: UserProfile) -> HttpResponse:
+ room_id = WebexOAuthProvider().maybe_generate_public_room_id(user)
+ payload: WebexAdhocMeetingPayload | WebexPersonalRoomMeetingPayload
+
+ # Quoting from https://developer.webex.com/meeting/docs/api/v1/meetings/create-a-meeting:
+ # An ad-hoc meeting is a non-recurring instant meeting for the target room
+ # which is supposed to be started immediately after being created for a
+ # quick collaboration.
+
+ # Public room IDs can only be generated if the user belongs to a paid Webex
+ # organization. They are necessary to generate ad-hoc Webex meetings which
+ # can be joined by anyone in the Webex organization. We fall back to
+ # generating a personal room meeting link if the user belongs to a free
+ # Webex organization.
+ if room_id is not None:
+ payload = WebexAdhocMeetingPayload(adhoc=True, roomId=room_id, title="Webex Ad-hoc meeting")
+ else:
+ start_time = timezone_now()
+ end_time = start_time + datetime.timedelta(minutes=40)
+ payload = WebexPersonalRoomMeetingPayload(
+ scheduledType="personalRoomMeeting",
+ start=start_time.isoformat(timespec="seconds"),
+ end=end_time.isoformat(timespec="seconds"),
+ title="Webex Personal Room Meeting",
+ )
+
+ return WebexOAuthProvider().make_video_call(request, user, payload=payload)
+
+
@csrf_exempt
@require_POST
@typed_endpoint_without_parameters
diff --git a/zproject/default_settings.py b/zproject/default_settings.py
index 1db1ba355d0..952a2b70d6f 100644
--- a/zproject/default_settings.py
+++ b/zproject/default_settings.py
@@ -127,6 +127,9 @@ VIDEO_ZOOM_OAUTH_URL: str = "https://zoom.us"
VIDEO_ZOOM_SERVER_TO_SERVER_ACCOUNT_ID = get_secret("video_zoom_account_id", development_only=True)
VIDEO_ZOOM_CLIENT_ID = get_secret("video_zoom_client_id", development_only=True)
VIDEO_ZOOM_CLIENT_SECRET = get_secret("video_zoom_client_secret")
+VIDEO_WEBEX_API_URL: str = "https://webexapis.com/v1/"
+VIDEO_WEBEX_CLIENT_ID = get_secret("video_webex_client_id", development_only=True)
+VIDEO_WEBEX_CLIENT_SECRET = get_secret("video_webex_client_secret")
# Email gateway
EMAIL_GATEWAY_PATTERN = ""
diff --git a/zproject/prod_settings_template.py b/zproject/prod_settings_template.py
index a9ea698f6df..22e15751027 100644
--- a/zproject/prod_settings_template.py
+++ b/zproject/prod_settings_template.py
@@ -780,6 +780,12 @@ SOCIAL_AUTH_SAML_SUPPORT_CONTACT = {
# VIDEO_ZOOM_OAUTH_URL = "https://zoom.example.com"
# VIDEO_ZOOM_API_URL = "https://api.zoom.example.com"
+## Controls the Webex video call integration. See:
+## https://zulip.readthedocs.io/en/latest/production/video-calls.html
+## You must also set video_webex_client_secret in
+## /etc/zulip/zulip-secrets.conf to enable Webex as a call provider.
+# VIDEO_WEBEX_CLIENT_ID = "<your Webex client ID>"
+
## Controls the Jitsi Meet video call integration. By default, the
## integration uses the SaaS https://meet.jit.si server. You can specify
## your own Jitsi Meet server, or if you'd like to disable the
diff --git a/zproject/test_extra_settings.py b/zproject/test_extra_settings.py
index 7e2e25519a6..3c3e44b8d9c 100644
--- a/zproject/test_extra_settings.py
+++ b/zproject/test_extra_settings.py
@@ -201,6 +201,9 @@ VIDEO_ZOOM_OAUTH_URL = "https://zoom.example.com"
VIDEO_ZOOM_CLIENT_ID = "client_id"
VIDEO_ZOOM_CLIENT_SECRET = "client_secret"
+VIDEO_WEBEX_CLIENT_ID = "client_id"
+VIDEO_WEBEX_CLIENT_SECRET = "client_secret"
+
BIG_BLUE_BUTTON_SECRET = "123"
BIG_BLUE_BUTTON_URL = "https://bbb.example.com/bigbluebutton/"
diff --git a/zproject/urls.py b/zproject/urls.py
index 4fb2ce24c27..fe37bc5d930 100644
--- a/zproject/urls.py
+++ b/zproject/urls.py
@@ -263,13 +263,16 @@ from zerver.views.users import (
update_user_by_id_api,
)
from zerver.views.video_calls import (
+ complete_webex_user,
complete_zoom_user,
create_nextcloud_talk_url,
deauthorize_zoom_user,
get_bigbluebutton_url,
join_bigbluebutton,
make_constructor_groups_video_call,
+ make_webex_video_call,
make_zoom_video_call,
+ register_webex_user,
register_zoom_user,
)
from zerver.views.welcome_bot_custom_message import send_test_welcome_bot_custom_message
@@ -593,6 +596,7 @@ v1_api_and_json_patterns = [
rest_path("register", POST=(events_register_backend, {"allow_anonymous_user_web"})),
# Used to generate a Zoom video call URL
rest_path("calls/zoom/create", POST=make_zoom_video_call),
+ rest_path("calls/webex/create", POST=make_webex_video_call),
# Used to generate a BigBlueButton video call URL
rest_path("calls/bigbluebutton/create", GET=get_bigbluebutton_url),
# Used to generate a Constructor Groups video call URL
@@ -729,6 +733,10 @@ i18n_urls = [
path("calls/zoom/register", register_zoom_user),
path("calls/zoom/complete", complete_zoom_user),
path("calls/zoom/deauthorize", deauthorize_zoom_user),
+ # Used to complete Webex OAuth flow to get user's
+ # access token.
+ path("calls/webex/register", register_webex_user),
+ path("calls/webex/complete", complete_webex_user),
# Used to join a BigBlueButton video call
path("calls/bigbluebutton/join", join_bigbluebutton),
# Integrations documentation