signalMessenger

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

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

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

README

signalMessenger

A Go implementation for communication over the signal messenger via dbus and AsamK/signal-cli

Install

Get this package with

go get gopkg.in/DerLukas15/signalMessenger.v0

Import this package with

import "gopkg.in/DerLukas15/signalMessenger.v0"

Usage

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 := signalMessenger.New(true, eventHandler)
	if err != nil {
		panic(err)
	}
	if conn == nil {
		panic(errors.New("No connection"))
	}
  for {
	}
}

See Examples for working implementations.

Documentation

Overview

Package signalMessenger 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.

Index

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 New

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

New creates a new connection object and starts the necessary routines. If no event handling is desired, nil can be used safely.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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