simplex-chat-nodejs: add member contact API methods (#6763)

* simplex-chat-nodejs: add apiCreateMemberContact and apiSendMemberContactInvitation

* simplex-chat-nodejs: add integration test for apiCreateMemberContact and apiSendMemberContactInvitation

Test creates a 3-user group with direct messages enabled, then verifies:
- apiCreateMemberContact creates a DM contact between group members
- apiSendMemberContactInvitation sends an invitation that the recipient receives

* simplex-chat-nodejs: bump @simplex-chat/types to ^0.4.0
This commit is contained in:
Narasimha-sc
2026-04-10 08:37:37 +00:00
committed by GitHub
parent e6dde90c40
commit e2ecff7215
3 changed files with 116 additions and 1 deletions

View File

@@ -872,4 +872,34 @@ export class ChatApi {
const r = await this.sendChatCmd(CC.APISetContactPrefs.cmdString({contactId, preferences}))
if (r.type !== "contactPrefsUpdated") throw new ChatCommandError("error setting contact prefs", r)
}
/**
* Create a direct message contact with a group member.
* Returns the created contact.
* Network usage: interactive.
*/
async apiCreateMemberContact(groupId: number, groupMemberId: number): Promise<T.Contact> {
const r: any = await this.sendChatCmd(`/_create member contact #${groupId} ${groupMemberId}`)
if (r.type === "newMemberContact") return r.contact
throw new ChatCommandError("error creating member contact", r)
}
/**
* Send a direct message invitation to a group member contact.
* The contact must have been created with {@link apiCreateMemberContact}.
* Network usage: interactive.
*/
async apiSendMemberContactInvitation(contactId: number, message?: T.MsgContent | string): Promise<T.Contact> {
let cmd = `/_invite member contact @${contactId}`
if (message !== undefined) {
if (typeof message === "string") {
cmd += ` text ${message}`
} else {
cmd += ` json ${JSON.stringify(message)}`
}
}
const r: any = await this.sendChatCmd(cmd)
if (r.type === "newMemberContactSentInv") return r.contact
throw new ChatCommandError("error sending member contact invitation", r)
}
}