gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

Add sendAs option to client.sendMessage

Open zeynalnia opened this issue 7 months ago • 0 comments

Closes #827.

Summary

Exposes the send_as parameter (already present on messages.sendMessage since layer 167) through the high-level client.sendMessage wrapper, so callers no longer need to drop down to client.invoke(new Api.messages.SendMessage(...)) just to post on behalf of a linked channel or anonymous-admin identity.

Changes

  • gramjs/client/messages.ts
    • Add sendAs?: EntityLike to SendMessageParams with JSDoc.
    • Resolve it via client.getInputEntity(sendAs) alongside the target entity.
    • Forward the resolved InputPeer to both Api.messages.SendMessage constructions (the Api.Message-resend branch and the fresh-text branch).
  • __tests__/client/sendMessage.spec.ts (new)
    • Two specs against a stub TelegramClient: (1) asserts sendAs is resolved and forwarded onto the constructed request, (2) asserts the field is left undefined when the option is omitted.

Scope

Limited to the no-file path. The file branch delegates to client.sendFile, which would need a separate change to thread sendAs through messages.SendMedia.

Test plan

  • [x] npx jest __tests__/client/sendMessage.spec.ts — both specs pass locally.
  • [ ] Manual smoke test against a Telegram account with permission to post as a linked channel.

zeynalnia avatar Apr 19 '26 07:04 zeynalnia