Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: v2
inputs:
# Pinned BSR commit (main @ spectrum-whatsapp-business 17e7e9c).
# Pinned BSR commit (main @ spectrum-whatsapp-business 2cab0fb).
# To pick up schema changes: update the ref, run `bun run generate`, commit both.
- module: buf.build/photon-hq/whatsapp:b218d3336d65421c8b215137797db344
- module: buf.build/photon-hq/whatsapp:ff29794be4d4464b9ae22fd1c90d8229
plugins:
- local: protoc-gen-ts_proto
out: src/generated
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@photon-ai/whatsapp-business",
"version": "0.2.0",
"version": "0.2.1",
"description": "TypeScript SDK for WhatsApp Business API via Spectrum",
"type": "module",
"exports": {
Expand Down
29 changes: 28 additions & 1 deletion src/generated/photon/whatsapp/v1/message_service.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export type {
ContactCardInput,
InteractiveInput,
LocationInput,
MarkReadOptions,
MediaInput,
MessageContent,
ReactionInput,
Expand Down
11 changes: 9 additions & 2 deletions src/resources/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { MessageServiceClient } from "../transport/grpc-client.ts";
import { mapSendParams } from "../transport/mapper.ts";
import type { RequestOptions } from "../types/client.ts";
import type {
MarkReadOptions,
SendMessageParams,
SendMessageResult,
} from "../types/messages.ts";
Expand Down Expand Up @@ -32,9 +33,15 @@ export class MessagesResource {
}
}

async markRead(messageId: string, options?: RequestOptions): Promise<void> {
async markRead(
messageId: string,
options?: RequestOptions & MarkReadOptions
): Promise<void> {
try {
await this._client.markRead({ messageId }, { signal: options?.signal });
await this._client.markRead(
{ messageId, typingIndicator: options?.typingIndicator ?? false },
{ signal: options?.signal }
);
} catch (err) {
throw fromGrpcError(err);
}
Expand Down
14 changes: 14 additions & 0 deletions src/types/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,17 @@ export interface SendMessageResult {
readonly messageId: string;
readonly messageStatus: string;
}

// ---------------------------------------------------------------------------
// Mark read options
// ---------------------------------------------------------------------------

export interface MarkReadOptions {
/**
* Also display a typing indicator in the chat. Meta dismisses it after
* 25 seconds or when the business sends a message, whichever comes first —
* there is no explicit "stop typing" call. The message being marked read
* must be an inbound message.
*/
readonly typingIndicator?: boolean;
}
29 changes: 29 additions & 0 deletions tests/unit/messages.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from "bun:test";
import type { MarkReadRequest } from "../../src/generated/photon/whatsapp/v1/message_service.ts";
import { MessagesResource } from "../../src/resources/messages.ts";
import type { MessageServiceClient } from "../../src/transport/grpc-client.ts";

function makeResource() {
const calls: MarkReadRequest[] = [];
const client = {
markRead: (request: MarkReadRequest) => {
calls.push(request);
return Promise.resolve({});
},
} as unknown as MessageServiceClient;
return { messages: new MessagesResource(client), calls };
}

describe("MessagesResource.markRead", () => {
it("sends a plain read receipt by default", async () => {
const { messages, calls } = makeResource();
await messages.markRead("wamid.abc");
expect(calls).toEqual([{ messageId: "wamid.abc", typingIndicator: false }]);
});

it("passes typingIndicator through when requested", async () => {
const { messages, calls } = makeResource();
await messages.markRead("wamid.abc", { typingIndicator: true });
expect(calls).toEqual([{ messageId: "wamid.abc", typingIndicator: true }]);
});
});
Loading