This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
thrempp/component/threema/main.go

49 lines
1010 B
Go
Raw Normal View History

2019-05-31 10:07:40 +02:00
package threema
2019-05-31 13:53:44 +02:00
import (
2019-05-31 14:36:18 +02:00
"strings"
"github.com/bdlm/log"
2019-05-31 13:53:44 +02:00
"gosrc.io/xmpp"
2019-05-31 14:36:18 +02:00
"dev.sum7.eu/genofire/thrempp/component"
2019-05-31 13:53:44 +02:00
)
2019-05-31 10:07:40 +02:00
type Threema struct {
component.Component
2019-05-31 14:36:18 +02:00
out chan xmpp.Packet
2019-05-31 10:07:40 +02:00
}
func NewThreema(config map[string]interface{}) (component.Component, error) {
return &Threema{}, nil
}
2019-05-31 13:53:44 +02:00
func (t *Threema) Connect() (chan xmpp.Packet, error) {
2019-05-31 14:36:18 +02:00
t.out = make(chan xmpp.Packet)
return t.out, nil
}
func (t *Threema) Send(packet xmpp.Packet) {
switch p := packet.(type) {
case xmpp.Message:
attrs := p.PacketAttrs
account := t.getAccount(attrs.From)
log.WithFields(map[string]interface{}{
"from": attrs.From,
"to": attrs.To,
}).Debug(p.Body)
threemaID := strings.ToUpper(strings.Split(attrs.To, "@")[0])
err := account.Send(threemaID, p.Body)
if err != nil {
msg := xmpp.NewMessage("chat", "", attrs.From, "", "en")
msg.Body = err.Error()
t.out <- msg
}
default:
log.Warnf("unkown package%v", p)
}
2019-05-31 13:53:44 +02:00
}
2019-05-31 10:07:40 +02:00
func init() {
component.AddComponent("threema", NewThreema)
}