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 ¶
- type Connection
- func (conn *Connection) Close()
- func (conn *Connection) SendMessage(target, message string, attachments []string) (int64, error)
- func (conn *Connection) SendMessageASync(target, message string, attachments []string) error
- func (conn *Connection) SetEventHandler(eventHandler Event) (err error)
- func (conn *Connection) SetLogger(logger *logrus.Entry) (err error)
- type Event
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.