signalgo

package module
v0.0.0-...-bdf2c26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

Go Reference GitHub GitHub go.mod Go version (branch) GitHub last commit GitHub top language GitHub release (latest by date)

signalgo

A Go interface for communicating over the signal messenger with the help of AsamK/signal-cli.

There are currently some limitations when using the dbus connection method, as the dbus implementation of signal-cli is still experimental. Those are e.g.:

  • Registered as normal messages without any text:
    • Remote delete messages
    • Group changes
  • Setting registration pin is not supported
  • ...

One should use the CLI connection method if those information and features are required.

Install

Get this package with

go get gopkg.in/DerLukas15/signalgo.v0

Import this package with

import "github.com/DerLukas15/signalgo"

Usage with DBus

Run signal-cli as a deamon.

Create a struct which satisfies the Event interface:

type eventHandler struct {}

func (eH *eventHandler) OnMessage(source, message string, attachments []string, messagetimestamp int64) error {
	fmt.Println("Got Message ", message, " (", messagetimestamp, ") from ", source, " with attachments ", attachments)
	return nil
}

func (eH *eventHandler) OnMessageRead(source string, messagetimestamp int64) error {
	fmt.Println("Message from ", source, " with timestamp ", messagetimestamp, " has been received")
	return nil
}

Now Initialize the package with the eventHandler and everything should work if the signal-cli is installed correctly.

func main() {
	eventHandler := &eventHandler{}
	conn, err := signalgo.NewDBus(true, eventHandler)
	if err != nil {
		panic(err)
	}
	if conn == nil {
		panic(errors.New("No connection"))
	}
  for {
	}
}

See GoDoc for examples.

Documentation

Overview

Package signalgo provides a dbus interface to talk to the signal-cli from https://github.com/AsamK/signal-cli.

Using DBus should be preferred as it guarantees fixed formating and type definitions. Furthermore, more processes can use the signal-cli simultaneously when using the DBus implementation. Systembus or Sessionbus are both possible to choose from during the creation. Message handling and other events are managed through the Event interface.

Copyright 2021 Lukas Gallandi. All rights reserved. Use of this source code is governed by a license that can be found in the LICENSE file.

Example (SystemDBus)
package main

import (
	"errors"
	"fmt"

	"github.com/DerLukas15/signalgo"
)

type eventHandler struct{}

func (eH *eventHandler) OnMessage(source, message string, attachments []string, messagetimestamp int64) error {
	fmt.Println("Got Message ", message, " (", messagetimestamp, ") from ", source, " with attachments ", attachments)
	return nil
}

func (eH *eventHandler) OnMessageRead(source string, messagetimestamp int64) error {
	fmt.Println("Message from ", source, " with timestamp ", messagetimestamp, " has been received")
	return nil
}

func main() {
	eventHandler := &eventHandler{}
	conn, err := signalgo.NewDBus(true, eventHandler)
	if err != nil {
		panic(err)
	}
	if conn == nil {
		panic(errors.New("No connection"))
	}
	for {
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection is the main struct which stores necessary information and is used for controlling and using the signalMessenger.

func NewCLI

func NewCLI(executablePath string, eventHandler Event) (conn *Connection, err error)

NewCLI creates a new connection object which connects to signal-cli via CLI and starts the necessary routines. The executablePath should be absolute.

Example
package main

import (
	"errors"

	"github.com/DerLukas15/signalgo"
)

func main() {
	conn, err := signalgo.NewCLI("PathToExecutable", nil)
	if err != nil {
		panic(err)
	}
	if conn == nil {
		panic(errors.New("No connection"))
	}
}
Output:

func NewDBus

func NewDBus(useSystembus bool, eventHandler Event) (conn *Connection, err error)

NewDBus creates a new connection object which connects to signal-cli via DBus and starts the necessary routines.

Example (SessionBus)
package main

import (
	"errors"

	"github.com/DerLukas15/signalgo"
)

func main() {
	conn, err := signalgo.NewDBus(false, nil)
	if err != nil {
		panic(err)
	}
	if conn == nil {
		panic(errors.New("No connection"))
	}
}
Output:

Example (SystemBus)
package main

import (
	"errors"

	"github.com/DerLukas15/signalgo"
)

func main() {
	conn, err := signalgo.NewDBus(true, nil)
	if err != nil {
		panic(err)
	}
	if conn == nil {
		panic(errors.New("No connection"))
	}
}
Output:

func (*Connection) Close

func (conn *Connection) Close()

Close closes the connection to the DBus and stopes all running routines.

func (*Connection) SendMessage

func (conn *Connection) SendMessage(target, message string, attachments []string) (int64, error)

SendMessage sends a new message to the target with possible attachments. This function waits for the message timestamp. The timestamp of the message given by signal-cli will be returned.

func (*Connection) SendMessageASync

func (conn *Connection) SendMessageASync(target, message string, attachments []string) error

SendMessageASync sends a new message to the target but does not care about the returning messageTimestamp.

func (*Connection) SetEventHandler

func (conn *Connection) SetEventHandler(eventHandler Event) (err error)

SetEventHandler sets a new eventHandler for the connection.

func (*Connection) SetLogger

func (conn *Connection) SetLogger(logger *logrus.Entry) (err error)

SetLogger sets a new logger for the connection.

type Event

type Event interface {
	OnMessage(source, message string, attachments []string, messagetimestamp int64) error
	OnMessageRead(source string, messagetimestamp int64) error
}

Event defines all the possible Methods which can be called depending on the received DBus events.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL