Categorygithub.com/status-im/status-go-sdk
modulepackage
0.0.0-20180716145249-b1a2ec4d2db5
Repository: https://github.com/status-im/status-go-sdk.git
Documentation: pkg.go.dev

# README

status-go-sdk

Note about the api stability: this package is under heavy development, and it's not intended for production purposes. Its api may change without previous notice.

This package provides an easy way to interact with status messaging system. This package allows you to create applications that interact with the status messaging system

Motivation

This library was initially created to have a low-dependency way to interact with status messaging system.

Build status

TBD

Features

This project is under heavy development process, here is a list of supported features:

Status messaging basic interaction

  • Setup a new connection
  • Close a specific connection
  • Sign up on the platform
  • Login as a specific account
  • Documented API for basic sdk interaction

Public channels interaction

  • Join public channels
  • Publish messages on public channels
  • Subscribe to public channels
  • Unsubscribe from a public channel
  • Documented API for public channels interaction
  • Working examples for public channel interaction

Contact management

  • Invite new contact
  • Accept a contact request

1 to 1 messages interaction

  • Send 1 to 1 conversation
  • Subscribe to 1 to 1 conversation
  • Unsubscribe from a 1 to 1 conversation
  • Documented API for 1 to 1 conversation
  • Working examples for 1 to 1 conversations

Private groups interaction

  • Publish messages on private groups
  • Subscribe to private groups
  • Unsubscribe from a private groups
  • Documented API for private groups interaction
  • Working examples for private groups interaction

Code Example

You'll find some code examples on the examples folder

Installation

status-go-sdk is a lightweight dependency package, that means we try to avoid as much external dependencies as possible. You can install it by running:

go get github.com/status-im/status-go-sdk

However, and to run some examples or you may also want to install go-ethereum/rpc with

go get github.com/ethereum/go-ethereum/rpc

If you are developing, run:

make dev-deps

API Reference

TBD

Tests

status-go-sdk currently runs tests under

make test

End-to-end tests are still in the works

How to use?

status-go-sdk relies on a running instance of statusd, we can quickly configure it by following its official instructions, but you can use this as a quick-start:

# Clone status-go
mkdir $GOPATH/src/status-im/
cd $GOPATH/src/status-im/
git clone [email protected]:status-im/status-go.git
cd status-go

# Build it and run it
 make statusgo && ./build/bin/statusd -shh=true -standalone=false -http=true -status=http -networkid=1

With this you'll have a statusd server running on 8545 port.

status-go-sdk receives as parameter an RPCClient interface, this allows you to use it in many different ways, here we will use a basic example relying on go-ethereum/rpc client.

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/ethereum/go-ethereum/rpc"
	"github.com/status-im/status-go-sdk"
)

func main() {
  // Here we create a new remote client against our running statusd
	rpcClient, err := rpc.Dial("http://localhost:8545")
	checkErr(err)

  // Setting up a new sdk client
	client := sdk.New(rpcClient)

  // We signup and login as a new account
	a, err := client.SignupAndLogin("password")
	checkErr(err)

  // Joining a new channel
	ch, err := a.JoinPublicChannel("my_channel")
	checkErr(err)

  // We will be sending messages to that channel every 3 seconds
	for range time.Tick(3 * time.Second) {
		message := fmt.Sprintf("PING : %d", time.Now().Unix())
		_ = ch.Publish(message)
	}
}

func checkErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

If you want to subscribe to this same channel you could easily do it with Subscribe method like:

_, _ = ch.Subscribe(func(m *sdk.Msg) {
  log.Println("Message from ", m.From, " with body: ", m.Raw)

  if strings.Contains(m.Raw, "PING :") {
    time.Sleep(5 * time.Second)
    message := fmt.Sprintf("PONG : %d", time.Now().Unix())
    _ = ch.Publish(message)
  }
})

runtime.Goexit()

Please have a look at examples folder for some working examples

Contribute

Please check the contributing guideline.

License

Mozilla Public License 2.0

# Packages

No description provided by the author

# Functions

New creates a default SDK object.
NewMockRPCClient creates a new mock instance.

# Constants

ConfirmedContactRequestType message type for confirmedContactRequestFormat.
ContactRequestType message type for contactRequestFormat.
ContactUpdateType message type for contactUpdateMsg.
NewContactKeyType message type for newContactKeyFormat.
PNBroadcastAvailabilityType message type for push notification broadcast availability.
PNRegistrationConfirmationType message type to allow a push notification server confirm a registration.
PNRegistrationType message type for sending a registration request to a push notification server.
SeenType message type for SeentType.
StandardMessageType message type for StandardMessageFormat.

# Structs

Account represents a logged in user on statusd node.
Channel : ...
ConfirmedContactMsg parsed struct for ConfirmedContactRequestType.
Contact details for a known user.
ContactMsg parsed struct for ContactRequestType.
ContactUpdateMsg parsed struct for ContactUpdateType.
Message message to be sent though ssh_post calls.
MockRPCClient is a mock of RPCClient interface.
MockRPCClientMockRecorder is the mock recorder for MockRPCClient.
Msg is a structure used by Subscribers and Publish().
NewContactKeyMsg parsed struct for NewContactKeyType.
NewMessageFilterResponse NewMessageFilter json response.
PNBroadcastAvailabilityMsg parsed struct for PNBroadcastAvailabilityType.
PNRegistrationConfirmationMsg parsed struct for PNRegistrationConfirmationType.
PNRegistrationMsg parsed struct for PNRegistrationType.
PublishMsg representation of a StandardMessageType.
Request json request.
SDK is a set of tools to interact with status node.
SeenMsg parsed struct for SeenType.
Subscription is a polling helper for a specific channel.

# Interfaces

RPCClient is a client to manage all rpc calls.

# Type aliases

ContactRequestHandler handler for contact requests.
MsgHandler is a callback function that processes messages delivered to asynchronous subscribers.