Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(sdk): expose the call-link route in all five clients

Yudhi Armyndharisa7e1ce32f23d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6d2dc873..a053b4c89 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The JavaScript, Python, PHP, Go and Java SDKs expose `PUT /sessions/:id/presence`, which sets the account's own global presence — not a chat's; the per-chat typing and recording states are unchanged.
- The JavaScript, Python, PHP, Go and Java SDKs expose the three group membership-request routes — list, approve and reject; omitting the participant list acts on every pending request, and a partial refusal still answers `200` with each outcome in `results`.
- The JavaScript, Python, PHP, Go and Java SDKs expose `GET /sessions/:sessionId/contacts/blocked` as `listBlocked` (`list_blocked` in Python), reading back what `block` and `unblock` have done. It needs only a read-level key.
+- The JavaScript, Python, PHP, Go and Java SDKs expose `POST /sessions/:sessionId/calls/link`, which creates a shareable WhatsApp call link. `startTime` is absolute epoch milliseconds and is required, so a link for right now carries the current timestamp rather than an omitted field.
### Fixed
diff --git a/docs/18-sdk-design.md b/docs/18-sdk-design.md
index 100d30223..d9e95f54b 100644
--- a/docs/18-sdk-design.md
+++ b/docs/18-sdk-design.md
@@ -41,7 +41,7 @@ All five SDKs expose the same fluent surface:
| `search` | search |
| `templates` | list, get, create, update, delete |
| `profile` | setProfileName, setProfileStatus, setProfilePicture |
-| `calls` | rejectCall |
+| `calls` | rejectCall, createLink |
| `media` | conversionStatus, convertVoice, convertVideo _(OPERATOR)_ |
| `health` | check, live, ready |
@@ -324,6 +324,7 @@ Media bodies share the `SendMediaRequest` shape: `{ chatId, url? | base64?, mime
| Method | Signature | Description |
| ------------ | ------------------------------- | -------------------------------------------------------------------------------------------- |
| `rejectCall` | `rejectCall(sessionId, callId)` | Reject a ringing incoming call (`callId` comes from the `call.received` event). **OPERATOR** |
+| `createLink` | `createLink(sessionId, body)` | Create a shareable WhatsApp call link (`startTime` is epoch MILLISECONDS). **OPERATOR** |
#### `media`
@@ -683,9 +684,10 @@ Resources are accessed as properties on the client (e.g. `client.messages`). All
#### `client.calls`
-| Method | Signature | Description |
-| ------------- | --------------------------------------------------- | -------------------------------------------- |
-| `reject_call` | `reject_call(session_id, call_id) -> SuccessResult` | Reject a ringing incoming call. **OPERATOR** |
+| Method | Signature | Description |
+| ------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------- |
+| `reject_call` | `reject_call(session_id, call_id) -> SuccessResult` | Reject a ringing incoming call. **OPERATOR** |
+| `create_link` | `create_link(session_id, body) -> CallLinkResponse` | Create a shareable WhatsApp call link (`startTime` is epoch MILLISECONDS). **OPERATOR** |
#### `client.media`
@@ -1023,6 +1025,7 @@ All payloads are associative arrays; all listed methods are synchronous and retu
| Method | Signature | Description |
| ------------ | ------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
| `rejectCall` | `rejectCall(string $sessionId, string $callId): array` | Reject a ringing incoming call (404 when it is not found or no longer ringing). **OPERATOR** |
+| `createLink` | `createLink(string $sessionId, array $body): array` | Create a shareable WhatsApp call link (`startTime` is epoch MILLISECONDS). **OPERATOR** |
#### `media`
diff --git a/sdk/README.md b/sdk/README.md
index 91b121cc8..8bb1ba611 100644
--- a/sdk/README.md
+++ b/sdk/README.md
@@ -37,7 +37,7 @@ All five SDKs expose the same fluent resource surface:
| `search` | search _(Operator)_ |
| `templates` | list, get, create, update, delete |
| `profile` | setProfileName, setProfileStatus, setProfilePicture _(OPERATOR)_ |
-| `calls` | rejectCall _(OPERATOR)_ |
+| `calls` | rejectCall, createLink _(OPERATOR)_ |
| `media` | conversionStatus, convertVoice, convertVideo _(OPERATOR)_ |
| `health` | check, live, ready |
diff --git a/sdk/go/calls.go b/sdk/go/calls.go
index 16625f91f..0ad7cbbfb 100644
--- a/sdk/go/calls.go
+++ b/sdk/go/calls.go
@@ -6,6 +6,18 @@ import "context"
// Backed by src/modules/call/call.controller.ts.
type CallsService struct{ client *Client }
+// CreateCallLinkRequest is the body for CallsService.CreateLink. Type is "audio" or "video";
+// WhatsApp's own URL path for audio is /voice/. StartTime is absolute epoch MILLISECONDS.
+type CreateCallLinkRequest struct {
+ Type string `json:"type"`
+ StartTime float64 `json:"startTime"`
+}
+
+// CallLinkResponse carries the shareable WhatsApp call link.
+type CallLinkResponse struct {
+ Link string `json:"link"`
+}
+
func (s *CallsService) base(sessionID string) string {
return "/api/sessions/" + pathEscape(sessionID) + "/calls"
}
@@ -22,3 +34,20 @@ func (s *CallsService) RejectCall(ctx context.Context, sessionID, callID string)
}
return &out, nil
}
+
+// CreateLink creates a shareable WhatsApp call link.
+//
+// Both fields are required. StartTime is absolute epoch MILLISECONDS — a link for right now is the
+// current timestamp rather than a zero value, because whatsapp-web.js generates an event-linked call
+// and has no notion of "no start time". A WhatsApp-side failure answers 403 rather than a success
+// carrying an empty link.
+func (s *CallsService) CreateLink(
+ ctx context.Context, sessionID string, body CreateCallLinkRequest,
+) (*CallLinkResponse, error) {
+ var out CallLinkResponse
+ err := s.client.do(ctx, "POST", s.base(sessionID)+"/link", nil, body, &out)
+ if err != nil {
+ return nil, err
+ }
+ return &out, nil
+}
diff --git a/sdk/go/routing_test.go b/sdk/go/routing_test.go
index 473aceff0..20499fbc4 100644
--- a/sdk/go/routing_test.go
+++ b/sdk/go/routing_test.go
@@ -159,6 +159,7 @@ func TestRouting(t *testing.T) {
{"Profile.SetProfilePicture", func(c *Client) { c.Profile.SetProfilePicture(ctx, "s1", SetProfilePictureRequest{}) }, "PUT", "/api/sessions/s1/profile/picture"},
{"Calls.RejectCall", func(c *Client) { c.Calls.RejectCall(ctx, "s1", "call1") }, "POST", "/api/sessions/s1/calls/call1/reject"},
+ {"Calls.CreateLink", func(c *Client) { c.Calls.CreateLink(ctx, "s1", CreateCallLinkRequest{}) }, "POST", "/api/sessions/s1/calls/link"},
}
for _, tc := range cases {
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/CallLinkResponse.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/CallLinkResponse.java
new file mode 100644
index 000000000..5601f64c4
--- /dev/null
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/CallLinkResponse.java
@@ -0,0 +1,8 @@
+package com.rmyndharis.openwa.model;
+
+/**
+ * The shareable WhatsApp call link.
+ *
+ * @param link the finished {@code https://call.whatsapp.com/…} URL
+ */
+public record CallLinkResponse(String link) {}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/CreateCallLinkRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/CreateCallLinkRequest.java
new file mode 100644
index 000000000..bec18d46a
--- /dev/null
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/CreateCallLinkRequest.java
@@ -0,0 +1,34 @@
+package com.rmyndharis.openwa.model;
+
+/**
+ * Request body for creating a shareable WhatsApp call link.
+ *
+ * @param type {@code "audio"} or {@code "video"}; WhatsApp's own URL path for audio is {@code /voice/}
+ * @param startTime absolute epoch MILLISECONDS the call is scheduled to start at
+ */
+public record CreateCallLinkRequest(String type, Double startTime) {
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder {
+ private String type;
+ private Double startTime;
+
+ /** {@code "audio"} or {@code "video"}. */
+ public Builder type(String v) {
+ this.type = v;
+ return this;
+ }
+
+ /** Absolute epoch MILLISECONDS. A link for right now is the current timestamp. */
+ public Builder startTime(Double v) {
+ this.startTime = v;
+ return this;
+ }
+
+ public CreateCallLinkRequest build() {
+ return new CreateCallLinkRequest(type, startTime);
+ }
+ }
+}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/CallsResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/CallsResource.java
index 4a44b2e41..89d2319c4 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/CallsResource.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/CallsResource.java
@@ -5,6 +5,8 @@ import static com.rmyndharis.openwa.http.Http.encodeSegment;
import com.rmyndharis.openwa.OpenWAClient;
import com.rmyndharis.openwa.http.HttpMethod;
import com.rmyndharis.openwa.model.SuccessResult;
+import com.rmyndharis.openwa.model.CallLinkResponse;
+import com.rmyndharis.openwa.model.CreateCallLinkRequest;
/** Calls resource — incoming call handling. */
public final class CallsResource {
@@ -30,4 +32,21 @@ public final class CallsResource {
null,
SuccessResult.class);
}
+ /**
+ * Create a shareable WhatsApp call link.
+ *
+ * <p>Both fields are required. {@code startTime} is absolute epoch MILLISECONDS — a link for
+ * right now is the current timestamp rather than an omitted field, because whatsapp-web.js
+ * generates an event-linked call and has no notion of "no start time". A WhatsApp-side failure
+ * answers {@code 403} rather than a success carrying an empty link.
+ */
+ public CallLinkResponse createLink(String sessionId, CreateCallLinkRequest body) {
+ return client.request(
+ HttpMethod.POST,
+ "/api/sessions/" + encodeSegment(sessionId) + "/calls/link",
+ null,
+ body,
+ CallLinkResponse.class);
+ }
+
}
diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/CallsResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/CallsResourceTest.java
index af65d4880..042a8bf93 100644
--- a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/CallsResourceTest.java
+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/CallsResourceTest.java
@@ -9,6 +9,7 @@ import com.rmyndharis.openwa.OpenWAClient;
import com.rmyndharis.openwa.errors.OpenWANotFoundError;
import com.rmyndharis.openwa.http.HttpMethod;
import com.rmyndharis.openwa.support.MockTransport;
+import com.rmyndharis.openwa.model.CreateCallLinkRequest;
import org.junit.jupiter.api.Test;
class CallsResourceTest {
@@ -42,4 +43,15 @@ class CallsResourceTest {
tx.respond(404, "{\"statusCode\":404,\"message\":\"Call not found or no longer ringing\",\"error\":\"Not Found\"}");
assertThrows(OpenWANotFoundError.class, () -> client.calls.rejectCall("s", "call-123"));
}
+ @Test
+ void createLinkPostsToCallsLink() {
+ tx.respond(200, "{\"link\":\"https://call.whatsapp.com/video/AbC\"}");
+ var res = client.calls.createLink(
+ "s", CreateCallLinkRequest.builder().type("video").startTime(1800000000000.0).build());
+ assertEquals("http://h/api/sessions/s/calls/link", tx.lastRequest().url());
+ assertEquals(HttpMethod.POST, tx.lastRequest().method());
+ assertTrue(tx.lastRequest().body().contains("video"));
+ assertTrue(res.link().contains("call.whatsapp.com"));
+ }
+
}
diff --git a/sdk/javascript/src/resources/calls.ts b/sdk/javascript/src/resources/calls.ts
index 572eab0a1..2e56b75d6 100644
--- a/sdk/javascript/src/resources/calls.ts
+++ b/sdk/javascript/src/resources/calls.ts
@@ -7,7 +7,7 @@
import { encodeSegment } from '../http.js';
import type { OpenWAClient } from '../client.js';
-import type { SuccessResult } from '../types.js';
+import type { CallLinkResponse, CreateCallLinkRequest, SuccessResult } from '../types.js';
export class CallsResource {
constructor(private readonly client: OpenWAClient) {}
@@ -23,4 +23,20 @@ export class CallsResource {
path: `/api/sessions/${encodeSegment(sessionId)}/calls/${encodeSegment(callId)}/reject`,
});
}
+
+ /**
+ * Create a shareable WhatsApp call link.
+ *
+ * Both fields are required. `startTime` is absolute epoch MILLISECONDS — a link for right now is
+ * `Date.now()` rather than an omitted field, because whatsapp-web.js generates an event-linked
+ * call and has no notion of "no start time". A WhatsApp-side failure answers `403` rather than a
+ * success carrying an empty link.
+ */
+ createLink(sessionId: string, body: CreateCallLinkRequest): Promise<CallLinkResponse> {
+ return this.client.request<CallLinkResponse>({
+ method: 'POST',
+ path: `/api/sessions/${encodeSegment(sessionId)}/calls/link`,
+ body,
+ });
+ }
}
diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.ts
index f64f986d9..3698f6f52 100644
--- a/sdk/javascript/src/types.ts
+++ b/sdk/javascript/src/types.ts
@@ -816,6 +816,22 @@ export interface SetOwnPresenceRequest {
available: boolean;
}
+/** Which kind of call a link opens. WhatsApp's own URL path for `audio` is `/voice/`. */
+export type CallLinkType = 'audio' | 'video';
+
+/** Body for {@link CallsResource.createLink}. */
+export interface CreateCallLinkRequest {
+ type: CallLinkType;
+ /** Absolute epoch MILLISECONDS the call is scheduled to start at. */
+ startTime: number;
+}
+
+/** Result of {@link CallsResource.createLink}. */
+export interface CallLinkResponse {
+ /** The shareable WhatsApp call link. */
+ link: string;
+}
+
export interface MarkChatRequest {
chatId: Jid;
}
diff --git a/sdk/javascript/test/resources.test.ts b/sdk/javascript/test/resources.test.ts
index efeedaed2..3a6521e2e 100644
--- a/sdk/javascript/test/resources.test.ts
+++ b/sdk/javascript/test/resources.test.ts
@@ -418,6 +418,19 @@ describe('HealthResource + auth — exact paths', () => {
});
});
+describe('CallsResource — call link', () => {
+ it('createLink posts to /calls/link with the type and start time', async () => {
+ const t = new MockTransport().on('POST', /\/calls\/link$/, { body: { link: 'https://call.whatsapp.com/video/AbC' } });
+ const res = await client(t).calls.createLink('s', { type: 'video', startTime: 1800000000000 });
+
+ expect(t.lastCall!.method).toBe('POST');
+ // Session-wide: no call id in the path, and not the reject route.
+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/calls/link');
+ expect(t.lastCall!.body).toEqual({ type: 'video', startTime: 1800000000000 });
+ expect(res.link).toContain('call.whatsapp.com');
+ });
+});
+
describe('SearchResource — exact path and query forwarding', () => {
it('forwards params as a query string to /api/search', async () => {
const t = new MockTransport().on('GET', /\/search$/, {
diff --git a/sdk/php/src/Resources/CallsResource.php b/sdk/php/src/Resources/CallsResource.php
index a36320f79..1b6acd524 100644
--- a/sdk/php/src/Resources/CallsResource.php
+++ b/sdk/php/src/Resources/CallsResource.php
@@ -31,4 +31,20 @@ class CallsResource
{
return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/calls/{$this->http->encodeSegment($callId)}/reject");
}
+ /**
+ * Create a shareable WhatsApp call link.
+ *
+ * Both fields are required. `startTime` is absolute epoch MILLISECONDS — a link for right now is
+ * the current timestamp rather than an omitted field, because whatsapp-web.js generates an
+ * event-linked call and has no notion of "no start time". A WhatsApp-side failure answers `403`
+ * rather than a success carrying an empty link.
+ *
+ * @param array{type:string,startTime:int|float} $body
+ * @return array<string,mixed>
+ */
+ public function createLink(string $sessionId, array $body): array
+ {
+ return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/calls/link", [], $body);
+ }
+
}
diff --git a/sdk/php/tests/ResourcesTest.php b/sdk/php/tests/ResourcesTest.php
index 67e18b4bf..f375884e7 100644
--- a/sdk/php/tests/ResourcesTest.php
+++ b/sdk/php/tests/ResourcesTest.php
@@ -443,4 +443,16 @@ class ResourcesTest extends TestCase
$this->assertSame([], $backend->lastCall()['body']);
}
+ public function testCreateCallLink(): void
+ {
+ $backend = new MockBackend();
+ $backend->on(200, ['link' => 'https://call.whatsapp.com/video/AbC']);
+ $client = $backend->makeClient();
+ $res = $client->calls->createLink('s', ['type' => 'video', 'startTime' => 1800000000000]);
+ $this->assertSame('POST', $backend->lastCall()['method']);
+ $this->assertStringEndsWith('/sessions/s/calls/link', $backend->lastCall()['url']);
+ $this->assertSame(['type' => 'video', 'startTime' => 1800000000000], $backend->lastCall()['body']);
+ $this->assertStringContainsString('call.whatsapp.com', $res['link']);
+ }
+
}
diff --git a/sdk/python/openwa/resources/calls.py b/sdk/python/openwa/resources/calls.py
index 395690f1b..572614e5d 100644
--- a/sdk/python/openwa/resources/calls.py
+++ b/sdk/python/openwa/resources/calls.py
@@ -8,7 +8,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from .._http import quote_segment
-from ..types import SuccessResult
+from ..types import CallLinkResponse, CreateCallLinkRequest, SuccessResult
if TYPE_CHECKING:
from .._http import HttpExecutor
@@ -26,3 +26,13 @@ class CallsResource:
return self._http.request(
"POST", f"/api/sessions/{quote_segment(session_id)}/calls/{quote_segment(call_id)}/reject"
)
+
+ def create_link(self, session_id: str, body: CreateCallLinkRequest) -> CallLinkResponse:
+ """Create a shareable WhatsApp call link.
+
+ Both fields are required. ``startTime`` is absolute epoch MILLISECONDS — a link for right
+ now is the current timestamp rather than an omitted field, because whatsapp-web.js generates
+ an event-linked call and has no notion of "no start time". A WhatsApp-side failure answers
+ 403 rather than a success carrying an empty link.
+ """
+ return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/calls/link", body=body)
diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.py
index d635dc600..f5430ae19 100644
--- a/sdk/python/openwa/types.py
+++ b/sdk/python/openwa/types.py
@@ -48,6 +48,26 @@ class SetOwnPresenceRequest(TypedDict):
available: bool
+CallLinkType = Literal["audio", "video"]
+
+
+class CreateCallLinkRequest(TypedDict):
+ """Body for :meth:`CallsResource.create_link`.
+
+ ``start_time`` is absolute epoch MILLISECONDS; a link for right now is the current timestamp
+ rather than an omitted field.
+ """
+
+ type: CallLinkType
+ startTime: float
+
+
+class CallLinkResponse(TypedDict):
+ """The shareable WhatsApp call link."""
+
+ link: str
+
+
class SuccessResult(TypedDict, total=False):
success: bool
message: str
diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.py
index 532da405f..71c5d4d95 100644
--- a/sdk/python/tests/test_sdk.py
+++ b/sdk/python/tests/test_sdk.py
@@ -859,3 +859,15 @@ class TestGroupMembershipRequests:
client.groups.reject_membership_requests("s", "[email protected]")
assert backend.calls[-1].url.endswith("/membership-requests/reject")
assert backend.calls[-1].body == {}
+
+
+class TestCallLink:
+ def test_create_link(self):
+ backend = MockBackend()
+ backend.on("POST", "/calls/link", body={"link": "https://call.whatsapp.com/video/AbC"})
+ client = make_client(backend)
+ res = client.calls.create_link("s", {"type": "video", "startTime": 1800000000000})
+ assert backend.calls[-1].method == "POST"
+ assert backend.calls[-1].url.endswith("/sessions/s/calls/link")
+ assert backend.calls[-1].body == {"type": "video", "startTime": 1800000000000}
+ assert "call.whatsapp.com" in res["link"]