Skip to content

feat: add get hook event list #1586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 29, 2025
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
13 changes: 13 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import type {
GetCampaignOptions,
GetChannelTypeResponse,
GetCommandResponse,
GetHookEventsResponse,
GetImportResponse,
GetMessageAPIResponse,
GetMessageOptions,
Expand Down Expand Up @@ -148,6 +149,7 @@ import type {
PollVote,
PollVoteData,
PollVotesAPIResponse,
Product,
PushPreference,
PushProvider,
PushProviderConfig,
Expand Down Expand Up @@ -2164,6 +2166,17 @@ export class StreamChat {
});
}

/**
* getHookEvents - Get available events for hooks (webhook, SQS, and SNS)
*
* @param {Product[]} [products] Optional array of products to filter events by (e.g., [Product.Chat, Product.Video])
* @returns {Promise<GetHookEventsResponse>} Response containing available hook events
*/
async getHookEvents(products?: Product[]) {
const params = products && products.length > 0 ? { product: products.join(',') } : {};
return await this.get<GetHookEventsResponse>(this.baseURL + '/hook/events', params);
}

_addChannelConfig({ cid, config }: ChannelResponse) {
if (this._cacheEnabled()) {
this.configs[cid] = config;
Expand Down
17 changes: 17 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,23 @@ export type GetRateLimitsResponse = APIResponse & {
web?: RateLimitsMap;
};

export enum Product {
Chat = 'chat',
Video = 'video',
Moderation = 'moderation',
Feeds = 'feeds',
}

export type HookEvent = {
name: string;
description: string;
products: Product[];
};

export type GetHookEventsResponse = APIResponse & {
events: HookEvent[];
};

export type GetReactionsAPIResponse = APIResponse & {
reactions: ReactionResponse[];
};
Expand Down
62 changes: 62 additions & 0 deletions test/unit/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,4 +1128,66 @@ describe('X-Stream-Client header', () => {

expect(userAgent).toMatchInlineSnapshot(`"deprecated"`);
});

describe('getHookEvents', () => {
let clientGetSpy;

beforeEach(() => {
clientGetSpy = vi.spyOn(client, 'get').mockResolvedValue({});
});

it('should call get with correct URL and no params when no products specified', async () => {
await client.getHookEvents();

expect(clientGetSpy).toHaveBeenCalledTimes(1);
expect(clientGetSpy).toHaveBeenCalledWith(`${client.baseURL}/hook/events`, {});
});

it('should call get with correct URL and empty params when empty products array specified', async () => {
await client.getHookEvents([]);

expect(clientGetSpy).toHaveBeenCalledTimes(1);
expect(clientGetSpy).toHaveBeenCalledWith(`${client.baseURL}/hook/events`, {});
});

it('should call get with product params when products specified', async () => {
await client.getHookEvents(['chat', 'video']);

expect(clientGetSpy).toHaveBeenCalledTimes(1);
expect(clientGetSpy).toHaveBeenCalledWith(`${client.baseURL}/hook/events`, {
product: 'chat,video',
});
});

it('should call get with single product param', async () => {
await client.getHookEvents(['chat']);

expect(clientGetSpy).toHaveBeenCalledTimes(1);
expect(clientGetSpy).toHaveBeenCalledWith(`${client.baseURL}/hook/events`, {
product: 'chat',
});
});

it('should return the response from get', async () => {
const mockResponse = {
events: [
{
name: 'message.new',
description: 'When a new message is added',
products: ['chat'],
},
{
name: 'call.created',
description: 'The call was created',
products: ['video'],
},
],
};
clientGetSpy.mockResolvedValue(mockResponse);

const result = await client.getHookEvents(['chat', 'video']);

expect(result).toEqual(mockResponse);
});
});
});