Compare commits
No commits in common. "53b45ba214c009383e299c050efd062721be11ec" and "9f0ce0b66a577e190e286f295ddfc1b7ab3149df" have entirely different histories.
53b45ba214
...
9f0ce0b66a
3 changed files with 32 additions and 35 deletions
8
Jenkinsfile
vendored
8
Jenkinsfile
vendored
|
@ -7,21 +7,15 @@ pipeline {
|
||||||
}
|
}
|
||||||
environment {
|
environment {
|
||||||
XDG_CACHE_HOME = '/tmp/.cache'
|
XDG_CACHE_HOME = '/tmp/.cache'
|
||||||
CGO_ENABLED = 0
|
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('build') {
|
stage('build') {
|
||||||
steps {
|
steps {
|
||||||
mattermostSend "Build started - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
|
|
||||||
sh 'go build'
|
sh 'go build'
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
mattermostSend "Build success - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
|
archiveArtifacts artifacts: 'pnut-bridge', fingerprint: true
|
||||||
archiveArtifacts artifacts: 'pnut-bridge'
|
|
||||||
}
|
|
||||||
failure {
|
|
||||||
mattermostSend "Build failure - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
README.md
17
README.md
|
@ -1,14 +1,16 @@
|
||||||
# pnut-bridge
|
# pnut-bridge
|
||||||
|
|
||||||
A [matterbridge] API plugin allowing you to connect message channels on [pnut.io] to other supported chat services.
|
A [matterbridge] API plugin allowing you to connect message channels on pnut.io to other supported chat services.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Report bugs or submit patches via [email].
|
Report bugs or submit pull requests on [codeberg] or via email.
|
||||||
|
|
||||||
Join my public chat room for development discussion.
|
Join my public chat room for development discussion.
|
||||||
|
|
||||||
- [#devel:mcmillian.ems.host]
|
- [#dev:thrrgilag.ems.host]
|
||||||
|
- [xmpp:dev@groups.clacks.network]
|
||||||
|
- [#thrrgilag on Libera.Chat]
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -36,7 +38,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
```
|
```
|
||||||
|
|
||||||
[matterbridge]: https://github.com/42wim/matterbridge
|
[codeberg]: https://codeberg.org/thrrgilag/pnut-bridge
|
||||||
[pnut.io]: https://pnut.io
|
[#dev:thrrgilag.ems.host]: https://matrix.to/#/#dev:thrrgilag.ems.host
|
||||||
[email]: https://morgan.mcmillian.dev/contact
|
[xmpp:dev@groups.clacks.network]: xmpp:dev@groups.clacks.network?join
|
||||||
[#devel:mcmillian.ems.host]: https://matrix.to/#/#devel:mcmillian.ems.host
|
[#thrrgilag on Libera.Chat]: ircs://irc.libera.chat/#thrrgilag
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ var interrupt chan os.Signal
|
||||||
type Config struct {
|
type Config struct {
|
||||||
PnutAccessToken string `ini:"pnut_access_token"`
|
PnutAccessToken string `ini:"pnut_access_token"`
|
||||||
PnutUsername string `ini:"pnut_username"`
|
PnutUsername string `ini:"pnut_username"`
|
||||||
MbURL string `ini:"matterbridge_url"`
|
MbUrl string `ini:"matterbridge_url"`
|
||||||
MbToken string `ini:"matterbridge_token"`
|
MbToken string `ini:"matterbridge_token"`
|
||||||
Rooms []Room
|
Rooms []Room
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,11 @@ type Room struct {
|
||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
Timestamp int `json:"timestamp"`
|
Timestamp int `json:"timestamp"`
|
||||||
ID string `json:"id"`
|
Id string `json:"id"`
|
||||||
ChannelType string `json:"channel_type"`
|
ChannelType string `json:"channel_type"`
|
||||||
SubscriptionIds []string `json:"subscription_ids"`
|
SubscriptionIds []string `json:"subscription_ids"`
|
||||||
Stream Stream `json:"stream"`
|
Stream Stream `json:"stream"`
|
||||||
ConnectionID string `json:"connection_id"`
|
ConnectionId string `json:"connection_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stream struct {
|
type Stream struct {
|
||||||
|
@ -77,7 +77,7 @@ type MbMessage struct {
|
||||||
ParentID string `json:"parent_id"`
|
ParentID string `json:"parent_id"`
|
||||||
Timestamp string `json:"timestamp"`
|
Timestamp string `json:"timestamp"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Extra MbExtra `json:"extra"`
|
Extra MbExtra `json"extra"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MbExtra struct {
|
type MbExtra struct {
|
||||||
|
@ -104,14 +104,14 @@ type PnutOembed struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
URL string `json:"url"`
|
Url string `json:"url"`
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func subscribe(connectionID string, accessToken string, rooms []Room) {
|
func subscribe(connection_id string, access_token string, rooms []Room) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("connection_id", connectionID)
|
params.Set("connection_id", connection_id)
|
||||||
for _, _room := range rooms {
|
for _, _room := range rooms {
|
||||||
log.Printf(">> connecting channel %s ...", _room.ChannelID)
|
log.Printf(">> connecting channel %s ...", _room.ChannelID)
|
||||||
url := "https://api.pnut.io/v1/channels/" + _room.ChannelID + "/messages?" + params.Encode()
|
url := "https://api.pnut.io/v1/channels/" + _room.ChannelID + "/messages?" + params.Encode()
|
||||||
|
@ -120,7 +120,7 @@ func subscribe(connectionID string, accessToken string, rooms []Room) {
|
||||||
log.Println("!! unable to create request", err)
|
log.Println("!! unable to create request", err)
|
||||||
}
|
}
|
||||||
req.Header.Set("User-Agent", "pnut-bridge")
|
req.Header.Set("User-Agent", "pnut-bridge")
|
||||||
req.Header.Add("Authorization", "Bearer "+accessToken)
|
req.Header.Add("Authorization", "Bearer "+access_token)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -144,9 +144,9 @@ func receiveHandler(connection *websocket.Conn, conf *Config) {
|
||||||
if err := json.Unmarshal(msg, &m); err != nil {
|
if err := json.Unmarshal(msg, &m); err != nil {
|
||||||
log.Println("!! error unmarshaling msg", err)
|
log.Println("!! error unmarshaling msg", err)
|
||||||
}
|
}
|
||||||
if len(m.Meta.ConnectionID) > 0 {
|
if len(m.Meta.ConnectionId) > 0 {
|
||||||
log.Println("<< connection", m.Meta.ConnectionID)
|
log.Println("<< connection", m.Meta.ConnectionId)
|
||||||
subscribe(m.Meta.ConnectionID, conf.PnutAccessToken, conf.Rooms)
|
subscribe(m.Meta.ConnectionId, conf.PnutAccessToken, conf.Rooms)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch m.Meta.ChannelType {
|
switch m.Meta.ChannelType {
|
||||||
|
@ -182,7 +182,7 @@ func pnutMsgHandler(conf *Config, msg woodstock.Message) {
|
||||||
log.Println("!! there is a problem creating json string", err)
|
log.Println("!! there is a problem creating json string", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
url := conf.MbURL + "/api/message"
|
url := conf.MbUrl + "/api/message"
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("!! unable to create request", err)
|
log.Println("!! unable to create request", err)
|
||||||
|
@ -199,9 +199,9 @@ func pnutMsgHandler(conf *Config, msg woodstock.Message) {
|
||||||
log.Printf("<< %s", resp.Status)
|
log.Printf("<< %s", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRoomGateway(rooms []Room, chanID string) string {
|
func getRoomGateway(rooms []Room, chan_id string) string {
|
||||||
for _, v := range rooms {
|
for _, v := range rooms {
|
||||||
if v.ChannelID == chanID {
|
if v.ChannelID == chan_id {
|
||||||
return v.Gateway
|
return v.Gateway
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ func getRoomGateway(rooms []Room, chanID string) string {
|
||||||
func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
||||||
client := woodstock.NewClient("", "")
|
client := woodstock.NewClient("", "")
|
||||||
client.SetAccessToken(conf.PnutAccessToken)
|
client.SetAccessToken(conf.PnutAccessToken)
|
||||||
channelID := getPnutChannel(conf.Rooms, msg.Gateway)
|
channel_id := getPnutChannel(conf.Rooms, msg.Gateway)
|
||||||
|
|
||||||
text := msg.Text
|
text := msg.Text
|
||||||
var raw []woodstock.Raw
|
var raw []woodstock.Raw
|
||||||
|
@ -231,7 +231,7 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
||||||
Version: "1.0",
|
Version: "1.0",
|
||||||
Type: "photo",
|
Type: "photo",
|
||||||
Title: file.Name,
|
Title: file.Name,
|
||||||
URL: file.URL,
|
Url: file.URL,
|
||||||
Width: im.Width,
|
Width: im.Width,
|
||||||
Height: im.Height,
|
Height: im.Height,
|
||||||
}
|
}
|
||||||
|
@ -247,9 +247,9 @@ func bridgeMsgHandler(conf *Config, msg MbMessage) {
|
||||||
lines := strings.Split(wrapped, "\n")
|
lines := strings.Split(wrapped, "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
line := msg.Username + " " + line
|
line := msg.Username + " " + line
|
||||||
log.Printf(">> sending message from %s to channel %s ...", msg.Gateway, channelID)
|
log.Printf(">> sending message from %s to channel %s ...", msg.Gateway, channel_id)
|
||||||
newmessage := woodstock.NewMessage{Text: line, Raw: raw}
|
newmessage := woodstock.NewMessage{Text: line, Raw: raw}
|
||||||
_, err := client.CreateMessage(channelID, newmessage)
|
_, err := client.CreateMessage(channel_id, newmessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("!! problem posting message to pnut.io", err)
|
log.Println("!! problem posting message to pnut.io", err)
|
||||||
}
|
}
|
||||||
|
@ -304,8 +304,8 @@ func main() {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("access_token", conf.PnutAccessToken)
|
params.Set("access_token", conf.PnutAccessToken)
|
||||||
|
|
||||||
socketURL := "wss://stream.pnut.io/v1/user?" + params.Encode()
|
socketUrl := "wss://stream.pnut.io/v1/user?" + params.Encode()
|
||||||
conn, _, err := websocket.DefaultDialer.Dial(socketURL, nil)
|
conn, _, err := websocket.DefaultDialer.Dial(socketUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("!! error connectiong to pnut.io:", err)
|
log.Fatal("!! error connectiong to pnut.io:", err)
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ func main() {
|
||||||
log.Fatal("!! error during write to websocket:", err)
|
log.Fatal("!! error during write to websocket:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
url := conf.MbURL + "/api/messages"
|
url := conf.MbUrl + "/api/messages"
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("!! unable to create request", err)
|
log.Println("!! unable to create request", err)
|
||||||
|
|
Loading…
Reference in a new issue