Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(channel): create a channel without a description for null
Yudhi Armyndharis2e55bb5e711f
diff --git a/src/modules/channel/channel.service.spec.ts b/src/modules/channel/channel.service.spec.tsindex ae5cd684f..216a2c1ad 100644--- a/src/modules/channel/channel.service.spec.ts+++ b/src/modules/channel/channel.service.spec.ts@@ -3,6 +3,8 @@ import { ChannelService } from './channel.service';import { ChannelNotFoundError } from '../../common/errors/channel-not-found.error';import { EngineRegistry } from '../../engine/engine-registry.service';import { IWhatsAppEngine } from '../../engine/interfaces/whatsapp-engine.interface';+import { WwebjsChannels } from '../../engine/adapters/wwebjs-channels';+import type { WwebjsEngineHost } from '../../engine/adapters/wwebjs-host';describe('ChannelService', () => {const makeService = (engine: Partial<IWhatsAppEngine> | undefined) => {@@ -45,6 +47,24 @@ describe('ChannelService', () => {expect(getChannelMessages).toHaveBeenCalledWith('ch1', expected);});+ it('answers a created channel without a description when the body sent null', async () => {+ const create = jest.fn().mockResolvedValue({ nid: { _serialized: '120363000@newsletter' }, title: 'News' });+ const host = {+ ensureReady: jest.fn(),+ getClient: () => ({ createChannel: create }),+ isPageTransportError: () => false,+ reportIfPageTransportError: jest.fn(),+ logger: { debug: jest.fn(), warn: jest.fn() },+ } as unknown as WwebjsEngineHost;+ const channels = new WwebjsChannels(host);+ const svc = makeService({ createChannel: (name, description) => channels.createChannel(name, description) });++ const created = await svc.createChannel('s1', 'News', null as unknown as string);++ expect(create).toHaveBeenCalledWith('News', {});+ expect(created).toEqual({ id: '120363000@newsletter', name: 'News' });+ });+it('demoteChannelAdmin forwards the channel and user to the engine, dropping the sessionId', async () => {const demoteChannelAdmin = jest.fn().mockResolvedValue(undefined);await makeService({ demoteChannelAdmin }).demoteChannelAdmin('s1', 'ch1@newsletter', '[email protected]');diff --git a/src/modules/channel/channel.service.ts b/src/modules/channel/channel.service.tsindex 12ac28746..65e5b3153 100644--- a/src/modules/channel/channel.service.ts+++ b/src/modules/channel/channel.service.ts@@ -45,7 +45,9 @@ export class ChannelService {/** Create a channel. The account owns it, which is what makes deleting it possible later. */createChannel(sessionId: string, name: string, description?: string) {- return this.getEngine(sessionId).createChannel(name, description);+ // The DTO lets a JSON null through as "no description". whatsapp-web.js echoes a non-undefined one back in+ // the created channel, which would answer `"description": null` for a field typed as an optional string.+ return this.getEngine(sessionId).createChannel(name, description ?? undefined);}/**