Initializing your client

Install your client

$ gem install "selfsdk"
$ go get github.com/joinself/self-go-sdk
$ npm install self-sdk

We currently offer support for some basic clients. We are always happy to receive contributions to review - send us a PR, or contact us at info@joinself.com to share what you have built with us!

LanguageURL
Gohttps://github.com/joinself/self-go-sdk
Rubyhttps://github.com/joinself/self-ruby-sdk/
Typescripthttps://github.com/joinself/self-typescript-sdk/

Referencing the SDK

SelfSDK is referenced like any other library for each specific language.

require "selfsdk"
import "github.com/joinself/self-go-sdk"
const SelfSDK = require("self-sdk");

Storage key generation

Self-SDK locally persists session and account information needed for end to end encryption. A SELF_STORAGE_KEY is required to securely encrypt this information. It is recommended that you use a large random string for your SELF_STORAGE_KEY. You can generate a random string through the command line with:

$ LC_ALL=C tr -dc '[:alnum:]' < /dev/urandom | head -c64

Keep that key in a secure place as you’ll need it to initialize a connection.

Basic connection

A basic connection to Self network only requires your SELF_APP_ID, SELF_APP_DEVICE_SECRET, SELF_STORAGE_KEY and SELF_STORAGE_DIR.

You may want to add SELF_APP_ID, SELF_APP_DEVICE_SECRET, SELF_STORAGE_KEY and SELF_STORAGE_DIR as environment variables.

@client = SelfSDK::App.new(ENV["SELF_APP_ID"], 
                           ENV["SELF_APP_DEVICE_SECRET"], 
                           ENV["SELF_STORAGE_KEY"], 
                           ENV["SELF_STORAGE_DIR"])
client, err := selfsdk.New(selfsdk.Config{
    SelfAppID:           os.Getenv("SELF_APP_ID"),
    SelfAppDeviceSecret: os.Getenv("SELF_APP_DEVICE_SECRET"),
    StorageKey:          os.Getenv("SELF_STORAGE_KEY"),
    StorageDir:          os.Getenv("SELF_STORAGE_DIR"),
})
const client = await SelfSDK.build( 
    os.Getenv("SELF_APP_ID"),
    os.Getenv("SELF_APP_DEVICE_SECRET"),
    os.Getenv("SELF_STORAGE_KEY"),
    os.Getenv("SELF_STORAGE_DIR"),

Custom environment

When you’re debugging your app, you may want to point to the sandbox environment instead of production to run your tests. You can define the environment by passing additional parameters to the Self client initialization.

@client = SelfSDK::App.new(ENV["SELF_APP_ID"], 
                           ENV["SELF_APP_DEVICE_SECRET"], 
                           ENV["SELF_STORAGE_KEY"], 
                           ENV["SELF_STORAGE_DIR"],
                           env: :sandbox)
client, err := selfsdk.New(selfsdk.Config{
    SelfAppID:           os.Getenv("SELF_APP_ID"),
    SelfAppDeviceSecret: os.Getenv("SELF_APP_DEVICE_SECRET"),
    StorageKey:          os.Getenv("SELF_STORAGE_KEY"),
    StorageDir:          os.Getenv("SELF_STORAGE_DIR"),
    Environment:	     "sandbox",
})
const client = await SelfSDK.build( 
    os.Getenv("SELF_APP_ID"),
    os.Getenv("SELF_APP_DEVICE_SECRET"),
    os.Getenv("SELF_STORAGE_KEY"),
    os.Getenv("SELF_STORAGE_DIR"),
    { 'env': 'sandbox' })

Reconnection

Self-SDK keeps a websocket connection open to self-messaging, but eventually, that connection may drop. By default Self-SDK will try to reconnect, but you can override this behaviour by passing custom parameters to initialization.

@client = SelfSDK::App.new(ENV["SELF_APP_ID"], 
                           ENV["SELF_APP_DEVICE_SECRET"], 
                           ENV["SELF_STORAGE_KEY"], 
                           ENV["SELF_STORAGE_DIR"],
                           auto_reconnect: false)
client, err := selfsdk.New(selfsdk.Config{
    SelfAppID:           os.Getenv("SELF_APP_ID"),
    SelfAppDeviceSecret: os.Getenv("SELF_APP_DEVICE_SECRET"),
    StorageKey:          os.Getenv("SELF_STORAGE_KEY"),
    StorageDir:          os.Getenv("SELF_STORAGE_DIR"),
    ReconnectAttempts:	 -1,
})
const client = await SelfSDK.build( 
    os.Getenv("SELF_APP_ID"),
    os.Getenv("SELF_APP_DEVICE_SECRET"),
    os.Getenv("SELF_STORAGE_KEY"),
    os.Getenv("SELF_STORAGE_DIR"),
    { 'autoReconnect': false })