Class: SessionClient

session-client~SessionClient(optionsopt)

new SessionClient(optionsopt)

Parameters:
Name Type Attributes Description
options object <optional>
Creation client options
Properties
Name Type Attributes Description
pollRate Number <optional>
How much delay between poll requests, Defaults: 1000
lastHash Number <optional>
lastHash Poll for messages from this hash on Defaults: '' (Read all messages)
homeServer Number <optional>
Which server holds your profile and attachments Defaults: https://file.getsession.org/
displayName Number <optional>
Send messages with this profile name, Defaults: false (Don't send a name)
Source:
Example
const sessionClient = new SessionClient()

Methods

(async) changeAvatar(data) → {Promise.<object>}

Change your avatar
Parameters:
Name Type Description
data Buffer image data
Source:
Returns:
avatar's URL and profileKey to decode
Type
Promise.<object>

close()

stop listening for messages
Source:

(async) decodeAvatar(url, profileKeyUint8) → {Promise.<Buffer>}

decode an avatar (usually from a message)
Parameters:
Name Type Description
url String Avatar URL
profileKeyUint8 Uint8Array
Source:
Returns:
a buffer containing raw binary data for image of avatar
Type
Promise.<Buffer>

deleteOpenGroupV2Message(open, message) → {Promise.<Array>}

Delete Open Group V2 Message
Parameters:
Name Type Description
open String group V2 handle
message Int ID to delete
Source:
Returns:
result of deletion (false, null or true)
Type
Promise.<Array>
Example
sessionClient.joinOpenGroup('chat.getsession.org')

deleteOpenGroupV3Message(open, message) → {Promise.<Array>}

Delete Open Group V3 Message
Parameters:
Name Type Description
open String group V3 handle
message Int ID to delete
Source:
Returns:
result of deletion (false, null or true)
Type
Promise.<Array>
Example
sessionClient.joinOpenGroup('chat.getsession.org')

(async) getAttachments(message) → {Promise.<Array>}

get and decrypt all attachments
Parameters:
Name Type Description
message Object message to download attachments from
Source:
Returns:
an array of buffers of downloaded data
Type
Promise.<Array>

(async) joinOpenGroupV2(open, open) → {Promise.<Object>}

Join Open Group V2, Receive Open Group V2 token
Parameters:
Name Type Description
open String group handle
open Number group Channel
Source:
Returns:
Object {token: {String}, channelId: {Int}, lastMessageId: {Int}}
Type
Promise.<Object>
Example
sessionClient.joinOpenGroup('chat.getsession.org')

(async) joinOpenGroupV3(open, open) → {Promise.<Object>}

Join Open Group V3, Receive Open Group V3 token
Parameters:
Name Type Description
open String group handle
open Number group Channel
Source:
Returns:
Object {token: {String}, channelId: {Int}, lastMessageId: {Int}}
Type
Promise.<Object>
Example
sessionClient.joinOpenGroupV3('chat.getsession.org')

(async) loadIdentity(options)

set an identity for this session client sets this.identityOutput
Parameters:
Name Type Description
options Object a list of options of how to set up the identity
Properties
Name Type Attributes Description
seed string <optional>
a space separate list of seed words
keypair Object <optional>
a buffer keypair
Properties
Name Type Description
privKey buffer a buffer that contains a curve25519-n private key
pubKey buffer a buffer that contains a curve25519-n public key
displayName string <optional>
use this string as the profile name for messages
avatarFile string <optional>
path to an image file to use as avatar
Source:
Example
client.loadIdentity({
  seed: fs.existsSync('seed.txt') && fs.readFileSync('seed.txt').toString(),
  //displayName: 'Sample Session Client',
  //avatarFile: 'avatar.png',
}).then(async() => {
  // Do stuff
})

(async) makeImageAttachment(data) → {Promise.<Object>}

get and decrypt all attachments
Parameters:
Name Type Description
data Buffer image data
Source:
Returns:
returns an attachmentPointer
Type
Promise.<Object>

(async) open()

start listening for messages
Source:

(async) poll()

poll storage server for messages and emit events
Source:
Fires:

(async) send(destination, messageTextBodyopt, optionsopt) → {Promise.<Bool>}

Send a Session message
Parameters:
Name Type Attributes Description
destination String pubkey of who you want to send to
messageTextBody String <optional>
text message to send
options object <optional>
Send options
Properties
Name Type Attributes Description
attachments object <optional>
Attachment Pointers to send
displayName String <optional>
Profile name to send as
avatar object <optional>
Avatar URL/ProfileKey to send
groupInvitation object <optional>
groupInvitation to send
flags object <optional>
message flags to set
nullMessage object <optional>
include a nullMessage
Source:
Returns:
If operation was successful or not
Type
Promise.<Bool>
Example
sessionClient.send('05d233c6c8daed63a48dfc872a6602512fd5a18fc764a6d75a08b9b25e7562851a', 'I didn\'t change the pubkey')

(async) sendOpenGroupInvite(destination, serverName, serverAddress, channelId) → {Promise.<Bool>}

Send an open group invite Currently works on desktop not on iOS/Android
Parameters:
Name Type Description
destination String pubkey of who you want to send to
serverName String Server description
serverAddress String Server URL
channelId Number Channel number
Source:
Returns:
If operation was successful or not
Type
Promise.<Bool>
Example
sessionClient.sendOpenGroupInvite('05d233c6c8daed63a48dfc872a6602512fd5a18fc764a6d75a08b9b25e7562851a', 'Session Chat', 'https://chat.getsession.org/', 1)

(async) sendOpenGroupV2Message(open)

Send Open Group V2 Message
Parameters:
Name Type Description
open String group handle
Source:
Example
sessionClient.joinOpenGroup('chat.getsession.org')

(async) sendOpenGroupV3Message(open)

Send Open Group V3 Message
Parameters:
Name Type Description
open String group handle
Source:
Example
sessionClient.joinOpenGroup('chat.getsession.org')

(async) sendSafeOpenGroupInvite(destination, serverName, serverAddress, channelId) → {Promise.<Bool>}

Send an open group invite with additional text for mobile seems to work with V2 (leave channel as 1)
Parameters:
Name Type Description
destination String pubkey of who you want to send to
serverName String Server description
serverAddress String Server URL
channelId Number Channel number
Source:
Returns:
If operation was successful or not
Type
Promise.<Bool>
Example
sessionClient.sendOpenGroupInvite('05d233c6c8daed63a48dfc872a6602512fd5a18fc764a6d75a08b9b25e7562851a', 'Session Chat', 'https://chat.getsession.org/', 1)