Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(messages): let callers suppress the link preview on send-text

Yudhi Armyndharis0cc0f47f5d57
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e1ce437a7..39ee06bc8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+- **`linkPreview` on `send-text`**, in all five SDKs and the MCP tool. Sending `false` suppresses the
+ URL preview on both engines.
+
+ It is documented as guaranteed **only in that direction**, because that is all the engines
+ actually agree on. Left unset it means "the engine default", and the defaults differ:
+ whatsapp-web.js asks WhatsApp Web to build a preview in-page, while Baileys builds none — its
+ preview generator is an optional package this project does not install. So `true` does not force a
+ preview onto Baileys; it only declines to suppress one, and saying otherwise would be a promise
+ nothing keeps.
+
+ A side effect worth knowing: Baileys wires that generator by default, so **every message
+ containing a URL currently attempts to load the missing package, fails, and logs a warning** before
+ sending without a preview. Passing `false` skips that path entirely.
+
+ Existing sends are byte-identical. A send with no preview choice keeps its exact previous call
+ shape rather than gaining a trailing `undefined`.
+
- **Preview a group before joining it:** `GET /api/sessions/:sessionId/groups/join-info?code=…`, in
all five SDKs. Supported on both engines. Read-only, so it is safe to call on a code from an
untrusted source — which is the point, since it is the step you want *before* `POST /groups/join`.
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index bf8b5cd8e..22384015f 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -1301,11 +1301,33 @@ Send a plain text message.
| chatId | string | Yes | non-empty | `[email protected]` or `[email protected]` |
| text | string | Yes | non-empty, max 4096 | Message text |
| mentions | string[] | No | array of WIDs | WIDs to @mention (e.g. `["[email protected]"]`). See **Mentions** below |
+| linkPreview | boolean | No | — | `false` suppresses the URL preview. See **Link previews** below |
```json
{ "chatId": "[email protected]", "text": "Hello from OpenWA!" }
```
+```json
+{ "chatId": "[email protected]", "text": "see https://example.com", "linkPreview": false }
+```
+
+**Link previews.** `linkPreview` is guaranteed **only in its suppressing direction**. Sending `false`
+stops the preview on both engines. Leaving it unset means "whatever the engine does by default", and
+the two engines genuinely differ:
+
+| | whatsapp-web.js | Baileys |
+| --- | --- | --- |
+| `linkPreview: false` | no preview | no preview |
+| unset / `true` | asks WhatsApp Web to build a preview in-page | **no preview** — its generator is an optional package this gateway does not install |
+
+So `true` does not force a preview onto Baileys; it only declines to suppress one. Sending `false` on
+Baileys additionally skips a generator call that currently fails and is swallowed with a warning on
+every message containing a URL.
+
+> whatsapp-web.js's own documentation notes the flag "has no effect on multi-device accounts". Its
+> code does act on the flag, but that caveat is upstream's and is repeated here rather than
+> contradicted — if a preview still appears on a multi-device account despite `false`, that is why.
+
```json
{ "chatId": "[email protected]", "text": "Hello @62811", "mentions": ["[email protected]"] }
```
diff --git a/openapi.json b/openapi.json
index 956202fdf..c41844ba9 100644
--- a/openapi.json
+++ b/openapi.json
@@ -7782,6 +7782,11 @@
"items": {
"type": "string"
}
+ },
+ "linkPreview": {
+ "type": "boolean",
+ "description": "Set `false` to suppress the URL preview. Guaranteed only in that direction: leaving it unset means whatever the engine does by default, and the engines differ — whatsapp-web.js asks WhatsApp Web to build a preview, while Baileys builds none unless its optional preview generator is installed. Sending `true` therefore does not force a preview on Baileys.",
+ "example": false
}
},
"required": [
diff --git a/sdk/go/types_message.go b/sdk/go/types_message.go
index 381831972..c1cdf1dde 100644
--- a/sdk/go/types_message.go
+++ b/sdk/go/types_message.go
@@ -15,6 +15,10 @@ type SendTextRequest struct {
// Mentions lists WIDs to @mention (e.g. ["[email protected]"]). The text must
// also contain the @<number> token.
Mentions []string `json:"mentions,omitempty"`
+ // LinkPreview set to false suppresses the URL preview. Guaranteed only in that direction: nil
+ // means the engine default, and the engines differ — whatsapp-web.js asks WhatsApp Web to build a
+ // preview, Baileys builds none unless its optional generator is installed.
+ LinkPreview *bool `json:"linkPreview,omitempty"`
}
// SendMediaRequest sends image/video/document/sticker media. Provide exactly
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendTextRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendTextRequest.java
index 10952204d..080176fd7 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendTextRequest.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendTextRequest.java
@@ -3,10 +3,15 @@ package com.rmyndharis.openwa.model;
import java.util.List;
/** Request body for sending a text message. */
-public record SendTextRequest(String chatId, String text, List<String> mentions) {
+public record SendTextRequest(String chatId, String text, List<String> mentions, Boolean linkPreview) {
/** Back-compatible constructor without mentions. */
public SendTextRequest(String chatId, String text) {
- this(chatId, text, null);
+ this(chatId, text, null, null);
+ }
+
+ /** Back-compatible constructor without a link-preview choice. */
+ public SendTextRequest(String chatId, String text, List<String> mentions) {
+ this(chatId, text, mentions, null);
}
public static Builder builder() {
@@ -17,6 +22,7 @@ public record SendTextRequest(String chatId, String text, List<String> mentions)
private String chatId;
private String text;
private List<String> mentions;
+ private Boolean linkPreview;
public Builder chatId(String v) {
this.chatId = v;
@@ -35,8 +41,18 @@ public record SendTextRequest(String chatId, String text, List<String> mentions)
return this;
}
+ /**
+ * {@code false} suppresses the URL preview. Guaranteed only in that direction: unset means the
+ * engine default, and the engines differ — whatsapp-web.js asks WhatsApp Web to build a
+ * preview, Baileys builds none unless its optional generator is installed.
+ */
+ public Builder linkPreview(Boolean v) {
+ this.linkPreview = v;
+ return this;
+ }
+
public SendTextRequest build() {
- return new SendTextRequest(chatId, text, mentions);
+ return new SendTextRequest(chatId, text, mentions, linkPreview);
}
}
}
diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.ts
index 37954fab1..483a9ec92 100644
--- a/sdk/javascript/src/types.ts
+++ b/sdk/javascript/src/types.ts
@@ -188,6 +188,12 @@ export interface SendTextRequest {
text: string;
/** WIDs to @mention (e.g. `["[email protected]"]`). The text must also contain the `@<number>` token. */
mentions?: string[];
+ /**
+ * Set `false` to suppress the URL preview. Guaranteed only in that direction: unset means the
+ * engine default, and the engines differ — whatsapp-web.js asks WhatsApp Web to build a preview,
+ * Baileys builds none unless its optional generator is installed.
+ */
+ linkPreview?: boolean;
}
export interface SendMediaRequest {
diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.py
index 259f7d765..2134859c8 100644
--- a/sdk/python/openwa/types.py
+++ b/sdk/python/openwa/types.py
@@ -192,6 +192,10 @@ class SendTextRequest(TypedDict, total=False):
text: str
# WIDs to @mention (e.g. ["[email protected]"]). The text must also contain the @<number> token.
mentions: list[str]
+ # Set False to suppress the URL preview. Guaranteed only in that direction: unset means the
+ # engine default, and the engines differ -- whatsapp-web.js asks WhatsApp Web to build a preview,
+ # Baileys builds none unless its optional generator is installed.
+ linkPreview: bool
class SendMediaRequest(TypedDict, total=False):
diff --git a/src/core/agent-tools/tools/message.tools.ts b/src/core/agent-tools/tools/message.tools.ts
index 271830a01..a5b9772cd 100644
--- a/src/core/agent-tools/tools/message.tools.ts
+++ b/src/core/agent-tools/tools/message.tools.ts
@@ -80,9 +80,20 @@ export function messageTools(message: MessageService): ToolDescriptor[] {
sessionId,
chatId: z.string().describe('Chat JID (e.g. [email protected] or [email protected])'),
text: z.string().min(1).max(4096).describe('Text message content'),
+ linkPreview: z
+ .boolean()
+ .optional()
+ .describe(
+ 'Set false to suppress the URL preview. Guaranteed only in that direction — leaving it ' +
+ 'unset means the engine default, and the engines differ.',
+ ),
}),
- handler: (input: { sessionId: string; chatId: string; text: string }) =>
- message.sendText(input.sessionId, { chatId: input.chatId, text: input.text }),
+ handler: (input: { sessionId: string; chatId: string; text: string; linkPreview?: boolean }) =>
+ message.sendText(input.sessionId, {
+ chatId: input.chatId,
+ text: input.text,
+ ...(input.linkPreview === undefined ? {} : { linkPreview: input.linkPreview }),
+ }),
},
{
name: 'MessageSendImage',
diff --git a/src/engine/adapters/baileys-messaging.ts b/src/engine/adapters/baileys-messaging.ts
index 836b7c40f..34f3bdf6c 100644
--- a/src/engine/adapters/baileys-messaging.ts
+++ b/src/engine/adapters/baileys-messaging.ts
@@ -77,11 +77,24 @@ export class BaileysMessaging {
return this.host.getSocket();
}
- async sendTextMessage(chatId: string, text: string, mentions?: string[]): Promise<MessageResult> {
+ async sendTextMessage(
+ chatId: string,
+ text: string,
+ mentions?: string[],
+ sendOptions?: { linkPreview?: boolean },
+ ): Promise<MessageResult> {
this.host.ensureReady();
const jid = await this.toDeliverableJid(chatId);
const options = this.withEphemeral(jid);
- const content = { text, ...this.withMentions(mentions) };
+ // `linkPreview: null` is Baileys' explicit "no preview": with the key absent it instead calls the
+ // configured generator (Utils/messages.js:279-281). Suppressing therefore also skips that call —
+ // which today fails anyway, since the generator dynamically imports an optional package this
+ // project does not install, and the failure is swallowed with a warn on every URL-bearing send.
+ const content = {
+ text,
+ ...this.withMentions(mentions),
+ ...(sendOptions?.linkPreview === false ? { linkPreview: null } : {}),
+ };
const sent = options
? await this.sock().sendMessage(jid, content, options)
: await this.sock().sendMessage(jid, content);
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.ts
index c4b631534..ab2596088 100644
--- a/src/engine/adapters/baileys.adapter.spec.ts
+++ b/src/engine/adapters/baileys.adapter.spec.ts
@@ -4600,3 +4600,53 @@ describe('BaileysAdapter call outcomes', () => {
await expect(adapter.rejectCall(CALL_ID)).rejects.toThrow(/CALL-1/);
});
});
+
+// `linkPreview: null` is Baileys' explicit "no preview". With the key absent it instead calls the
+// configured generator, which in this project dynamically imports a package that is not installed —
+// so suppressing also spares a failing import and a warn log on every URL-bearing send.
+describe('BaileysAdapter link preview', () => {
+ beforeEach(() => {
+ fakeSock.user = undefined;
+ fakeSock.resetEmitter();
+ jest.clearAllMocks();
+ });
+
+ const readyAdapter = async () => {
+ const adapter = newAdapter();
+ await adapter.initialize(noopCallbacks({}));
+ fakeSock.user = { id: '628999:[email protected]', name: 'Me' };
+ fakeSock.fire('connection.update', { connection: 'open' });
+ fakeSock.sendMessage.mockResolvedValue({ key: { id: 'M1' }, messageTimestamp: 1 });
+ return adapter;
+ };
+
+ const sentContent = (): Record<string, unknown> =>
+ (fakeSock.sendMessage.mock.calls[0] as [string, Record<string, unknown>])[1];
+
+ it('sends the explicit null that suppresses the preview', async () => {
+ const adapter = await readyAdapter();
+
+ await adapter.sendTextMessage('[email protected]', 'see https://example.com', undefined, { linkPreview: false });
+
+ expect(sentContent().linkPreview).toBeNull();
+ });
+
+ // The key must be ABSENT, not undefined-valued: Baileys branches on `typeof urlInfo === 'undefined'`
+ // to decide whether to generate, so either is equivalent — but leaving it out keeps the content
+ // object identical to what a plain send has always produced.
+ it('leaves the key out entirely when the preview is allowed', async () => {
+ const adapter = await readyAdapter();
+
+ await adapter.sendTextMessage('[email protected]', 'see https://example.com', undefined, { linkPreview: true });
+
+ expect(sentContent()).not.toHaveProperty('linkPreview');
+ });
+
+ it('leaves the key out for a plain send', async () => {
+ const adapter = await readyAdapter();
+
+ await adapter.sendTextMessage('[email protected]', 'hi');
+
+ expect(sentContent()).not.toHaveProperty('linkPreview');
+ });
+});
diff --git a/src/engine/adapters/baileys.adapter.ts b/src/engine/adapters/baileys.adapter.ts
index ef64aa3a4..98a0d6ce8 100644
--- a/src/engine/adapters/baileys.adapter.ts
+++ b/src/engine/adapters/baileys.adapter.ts
@@ -281,8 +281,13 @@ export class BaileysAdapter implements IWhatsAppEngine {
// ----- Messaging -----
- async sendTextMessage(chatId: string, text: string, mentions?: string[]): Promise<MessageResult> {
- return this.messaging.sendTextMessage(chatId, text, mentions);
+ async sendTextMessage(
+ chatId: string,
+ text: string,
+ mentions?: string[],
+ options?: { linkPreview?: boolean },
+ ): Promise<MessageResult> {
+ return this.messaging.sendTextMessage(chatId, text, mentions, options);
}
async checkNumberExists(number: string): Promise<boolean> {
diff --git a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
index 36539e4ba..99d804061 100644
--- a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
+++ b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
@@ -5858,3 +5858,42 @@ describe('WhatsAppWebJsAdapter group join-info', () => {
await expect(readyAdapter({ getInviteInfo }).getGroupJoinInfo('ABC')).rejects.toBeInstanceOf(GroupNotFoundError);
});
});
+
+// whatsapp-web.js reads the flag as `linkPreview === false ? undefined : true` (Client.js:1458), so
+// only an explicit false is worth forwarding — and forwarding it is what actually suppresses.
+describe('WhatsAppWebJsAdapter link preview', () => {
+ const readyAdapter = (client: unknown): WhatsAppWebJsAdapter => {
+ const adapter = new WhatsAppWebJsAdapter({ sessionId: 's', sessionDataPath: './data/sessions', puppeteer: {} });
+ (adapter as unknown as { status: EngineStatus }).status = EngineStatus.READY;
+ (adapter as unknown as { client: unknown }).client = client;
+ return adapter;
+ };
+
+ const sentOptions = (sendMessage: jest.Mock): unknown => (sendMessage.mock.calls[0] as unknown[] | undefined)?.[2];
+
+ it('forwards an explicit suppression', async () => {
+ const sendMessage = jest.fn().mockResolvedValue({ id: { _serialized: 'M1' }, timestamp: 1 });
+
+ await readyAdapter({ sendMessage }).sendTextMessage('[email protected]', 'hi', undefined, { linkPreview: false });
+
+ expect(sentOptions(sendMessage)).toEqual({ linkPreview: false });
+ });
+
+ // Passing true is identical to passing nothing, so sending an options object would add one to
+ // every plain send for no change in behaviour.
+ it('sends no options object when the preview is merely allowed', async () => {
+ const sendMessage = jest.fn().mockResolvedValue({ id: { _serialized: 'M1' }, timestamp: 1 });
+
+ await readyAdapter({ sendMessage }).sendTextMessage('[email protected]', 'hi', undefined, { linkPreview: true });
+
+ expect(sentOptions(sendMessage)).toBeUndefined();
+ });
+
+ it('keeps mentions working alongside a suppression', async () => {
+ const sendMessage = jest.fn().mockResolvedValue({ id: { _serialized: 'M1' }, timestamp: 1 });
+
+ await readyAdapter({ sendMessage }).sendTextMessage('[email protected]', 'hi', ['[email protected]'], { linkPreview: false });
+
+ expect(sentOptions(sendMessage)).toEqual({ mentions: ['[email protected]'], linkPreview: false });
+ });
+});
diff --git a/src/engine/adapters/whatsapp-web-js.adapter.ts b/src/engine/adapters/whatsapp-web-js.adapter.ts
index d8928cecc..6fb0d23d5 100644
--- a/src/engine/adapters/whatsapp-web-js.adapter.ts
+++ b/src/engine/adapters/whatsapp-web-js.adapter.ts
@@ -1336,8 +1336,13 @@ export class WhatsAppWebJsAdapter extends EventEmitter implements IWhatsAppEngin
return this.pushName;
}
- sendTextMessage(chatId: string, text: string, mentions?: string[]): Promise<MessageResult> {
- return this.messaging.sendTextMessage(chatId, text, mentions);
+ sendTextMessage(
+ chatId: string,
+ text: string,
+ mentions?: string[],
+ options?: { linkPreview?: boolean },
+ ): Promise<MessageResult> {
+ return this.messaging.sendTextMessage(chatId, text, mentions, options);
}
sendImageMessage(chatId: string, media: MediaInput): Promise<MessageResult> {
diff --git a/src/engine/adapters/wwebjs-messaging.ts b/src/engine/adapters/wwebjs-messaging.ts
index d2d036f8e..50d204c0d 100644
--- a/src/engine/adapters/wwebjs-messaging.ts
+++ b/src/engine/adapters/wwebjs-messaging.ts
@@ -266,12 +266,28 @@ export class WwebjsMessaging {
}
}
- async sendTextMessage(chatId: string, text: string, mentions?: string[]): Promise<MessageResult> {
+ async sendTextMessage(
+ chatId: string,
+ text: string,
+ mentions?: string[],
+ options?: { linkPreview?: boolean },
+ ): Promise<MessageResult> {
this.host.ensureReady();
// wwebjs accepts neutral `<phone>@c.us` WIDs directly as mentionedJidList, so no de-normalization
// is needed. Omit the options object entirely when none are given to keep today's send behavior.
+ //
+ // Only an explicit `false` is forwarded. whatsapp-web.js reads the flag as
+ // `linkPreview === false ? undefined : true` (Client.js:1458), so passing `true` is identical to
+ // passing nothing — sending it anyway would add an options object to every plain send for no
+ // change in behaviour.
+ const sendOptions: { mentions?: string[]; linkPreview?: boolean } = {};
+ if (mentions?.length) sendOptions.mentions = mentions;
+ if (options?.linkPreview === false) sendOptions.linkPreview = false;
+
const msg = await this.sendResolved(chatId, to =>
- mentions?.length ? this.client().sendMessage(to, text, { mentions }) : this.client().sendMessage(to, text),
+ Object.keys(sendOptions).length
+ ? this.client().sendMessage(to, text, sendOptions)
+ : this.client().sendMessage(to, text),
);
return toMessageResult(msg);
}
diff --git a/src/engine/interfaces/whatsapp-engine.interface.ts b/src/engine/interfaces/whatsapp-engine.interface.ts
index 31fc8020b..669e81a97 100644
--- a/src/engine/interfaces/whatsapp-engine.interface.ts
+++ b/src/engine/interfaces/whatsapp-engine.interface.ts
@@ -773,7 +773,21 @@ export interface IWhatsAppEngine {
getPushName(): string | null;
// Messaging - Basic
- sendTextMessage(chatId: string, text: string, mentions?: string[]): Promise<MessageResult>;
+ /**
+ * Send text.
+ *
+ * `linkPreview: false` suppresses the URL preview on BOTH engines. Leaving it unset means "whatever
+ * the engine does by default", and the two differ: whatsapp-web.js asks WhatsApp Web to build a
+ * preview in-page, while Baileys builds none unless its optional preview generator is installed.
+ * The parameter is therefore only guaranteed in its suppressing direction, and is documented as
+ * such rather than pretending at symmetry.
+ */
+ sendTextMessage(
+ chatId: string,
+ text: string,
+ mentions?: string[],
+ options?: { linkPreview?: boolean },
+ ): Promise<MessageResult>;
sendImageMessage(chatId: string, media: MediaInput): Promise<MessageResult>;
sendVideoMessage(chatId: string, media: MediaInput): Promise<MessageResult>;
sendAudioMessage(chatId: string, media: MediaInput): Promise<MessageResult>;
diff --git a/src/modules/message/dto/send-message.dto.ts b/src/modules/message/dto/send-message.dto.ts
index 644de7ad5..313ee3db4 100644
--- a/src/modules/message/dto/send-message.dto.ts
+++ b/src/modules/message/dto/send-message.dto.ts
@@ -45,6 +45,21 @@ export class SendTextMessageDto {
@IsString({ each: true })
@MaxLength(64, { each: true })
mentions?: string[];
+
+ @ApiPropertyOptional({
+ description:
+ 'Set `false` to suppress the URL preview. Guaranteed only in that direction: leaving it unset ' +
+ 'means whatever the engine does by default, and the engines differ — whatsapp-web.js asks ' +
+ 'WhatsApp Web to build a preview, while Baileys builds none unless its optional preview ' +
+ 'generator is installed. Sending `true` therefore does not force a preview on Baileys.',
+ example: false,
+ })
+ // Implicit conversion turns EVERY non-empty string into true, so an unguarded `false` sent as a
+ // string would request a preview instead of suppressing one — the opposite of what was asked.
+ @ToStrictBoolean()
+ @IsOptional()
+ @IsBoolean()
+ linkPreview?: boolean;
}
export class SendMediaMessageDto {
diff --git a/src/modules/message/message.service.spec.ts b/src/modules/message/message.service.spec.ts
index dc136efc0..681ed6049 100644
--- a/src/modules/message/message.service.spec.ts
+++ b/src/modules/message/message.service.spec.ts
@@ -173,6 +173,33 @@ describe('MessageService', () => {
expect(mockEngine.sendTextMessage).toHaveBeenCalledWith('[email protected]', 'hi @62811', ['[email protected]']);
});
+ // The parameter is only guaranteed in its suppressing direction, so what matters is that `false`
+ // reaches the engine and that everything else leaves the existing call shape alone.
+ it('threads a link-preview suppression through to the engine', async () => {
+ const input = { chatId: '[email protected]', text: 'see https://example.com', linkPreview: false };
+ (hookManager.execute as jest.Mock).mockResolvedValueOnce({
+ continue: true,
+ data: { sessionId: 'sess-1', input, type: 'text' },
+ });
+
+ await service.sendText('sess-1', input);
+
+ expect(mockEngine.sendTextMessage).toHaveBeenCalledWith(
+ 'see https://example.com',
+ undefined,
+ { linkPreview: false },
+ );
+ });
+
+ // A send that asks for nothing must keep the exact call it made before this option existed —
+ // a trailing undefined would be harmless to the engines but would rewrite every existing send.
+ it('leaves the plain send shape untouched when no preview choice is made', async () => {
+ await service.sendText('sess-1', { chatId: '[email protected]', text: 'hi' });
+
+ expect(mockEngine.sendTextMessage).toHaveBeenCalledWith('[email protected]', 'hi');
+ });
+
it('should save outgoing message as pending before sending, then update to sent', async () => {
await service.sendText('sess-1', {
chatId: '[email protected]',
diff --git a/src/modules/message/message.service.ts b/src/modules/message/message.service.ts
index b92ff3270..3b977c81e 100644
--- a/src/modules/message/message.service.ts
+++ b/src/modules/message/message.service.ts
@@ -125,10 +125,18 @@ export class MessageService {
let result: MessageResult;
try {
- // Keep the 2-arg call shape for plain sends; only pass mentions when the caller supplied any.
- result = finalDto.mentions?.length
- ? await engine.sendTextMessage(finalDto.chatId, finalDto.text, finalDto.mentions)
- : await engine.sendTextMessage(finalDto.chatId, finalDto.text);
+ // The call is widened ONLY as far as the caller actually asked. A send with neither mentions
+ // nor a preview choice keeps its two-argument shape, and one with mentions alone keeps its
+ // three — trailing `undefined`s would be harmless to the engines but would rewrite the call
+ // shape of every existing send for no behavioural gain.
+ const { linkPreview } = finalDto;
+ if (linkPreview !== undefined) {
+ result = await engine.sendTextMessage(finalDto.chatId, finalDto.text, finalDto.mentions, { linkPreview });
+ } else if (finalDto.mentions?.length) {
+ result = await engine.sendTextMessage(finalDto.chatId, finalDto.text, finalDto.mentions);
+ } else {
+ result = await engine.sendTextMessage(finalDto.chatId, finalDto.text);
+ }
} catch (error) {
// The SEND itself failed — mark FAILED + fire message:failed (a post-send persistence fault is
// handled separately by persistSentState and must NOT land here).