gramjs
gramjs copied to clipboard
Add sendAs option to client.sendMessage
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?: EntityLiketoSendMessageParamswith JSDoc. - Resolve it via
client.getInputEntity(sendAs)alongside the target entity. - Forward the resolved
InputPeerto bothApi.messages.SendMessageconstructions (theApi.Message-resend branch and the fresh-text branch).
- Add
__tests__/client/sendMessage.spec.ts(new)- Two specs against a stub
TelegramClient: (1) assertssendAsis resolved and forwarded onto the constructed request, (2) asserts the field is leftundefinedwhen the option is omitted.
- Two specs against a stub
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.