Categorygithub.com/selfid-net/self-messaging-client
repositorypackage
0.0.1
Repository: https://github.com/selfid-net/self-messaging-client.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

self messaging client GoDoc Go Report Card Build Status

A messaging client for go for use with self's messaging service

Installation

To start using this client, you can run:

$ go get github.com/selfid-net/self-messaging-client

Usage

To create a new messaging client

package main

import (
    messaging "github.com/selfid-net/self-messaging-client"
    msgproto "github.com/selfid-net/self-messaging-client/proto"
)

func main() {
    appID := "5d41402abc4b2a76b9719d911017c592" // the ID of your application
    device := "1"                               // the device identifier you are connecting as
    appKey := "secret-key"                      // the applications private key

    // create a new messaging client
    client, err := messaging.New("wss://messaging.selfid.net", appID, device, appKey)
}

Additional optional parameters can be specified to the client like:

func main() {
    ...

    client, err := messaging.New("wss://messaging.selfid.net", appID, device, appKey, messaging.AutoReconnect(true))
}

You can send a message by using the following:

func main() {
    ...

    msg := &msgproto.Message{
        Id: uuid.New().String(),                      // the id of the request
        Type: msgproto.MsgType_MSG,                   // the type of message
        Sender: "5d41402abc4b2a76b9719d911017c592:1", // constructed from app ID and device
        Recipient: "12345678910:aeH2o21",             // the recipients self ID and device
        Ciphertext: []byte("hello"),                  // the messages payload
    }

    err = client.Send(msg)
}

There are two ways to receive a message:

func main() {
    ...

    // read message
    for {
        msg, err := client.Receive()
    }

    // or read via channel
    mch := client.ReceiveChan()
    for {
        if !client.IsClosed() {
            return
        }

        msg := <-mch
    }
}

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, this project is maintained under the Semantic Versioning guidelines.

Copyright and License

Code and documentation copyright since 2019 Self ID LTD.

Code released under the MIT License.