Merge remote-tracking branch 'upstream/master' into issue-674
This commit is contained in:
@@ -62,7 +62,8 @@
|
|||||||
* [API](https://github.com/42wim/matterbridge/wiki/Features#api)
|
* [API](https://github.com/42wim/matterbridge/wiki/Features#api)
|
||||||
|
|
||||||
### API
|
### API
|
||||||
The API is very basic at the moment and rather undocumented.
|
The API is very basic at the moment.
|
||||||
|
More info on [swaggerhub](https://app.swaggerhub.com/apis-docs/matterbridge/matterbridge-api/0.1.0-oas3)
|
||||||
|
|
||||||
Used by at least 3 projects. Feel free to make a PR to add your project to this list.
|
Used by at least 3 projects. Feel free to make a PR to add your project to this list.
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package bdiscord
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -49,6 +50,7 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
|||||||
func (b *Bdiscord) Connect() error {
|
func (b *Bdiscord) Connect() error {
|
||||||
var err error
|
var err error
|
||||||
var token string
|
var token string
|
||||||
|
var guildFound bool
|
||||||
b.Log.Info("Connecting")
|
b.Log.Info("Connecting")
|
||||||
if b.GetString("WebhookURL") == "" {
|
if b.GetString("WebhookURL") == "" {
|
||||||
b.Log.Info("Connecting using token")
|
b.Log.Info("Connecting using token")
|
||||||
@@ -86,12 +88,24 @@ func (b *Bdiscord) Connect() error {
|
|||||||
if guild.Name == serverName || guild.ID == serverName {
|
if guild.Name == serverName || guild.ID == serverName {
|
||||||
b.channels, err = b.c.GuildChannels(guild.ID)
|
b.channels, err = b.c.GuildChannels(guild.ID)
|
||||||
b.guildID = guild.ID
|
b.guildID = guild.ID
|
||||||
|
guildFound = true
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.channelsMutex.Unlock()
|
b.channelsMutex.Unlock()
|
||||||
|
if !guildFound {
|
||||||
|
msg := fmt.Sprintf("Server \"%s\" not found", b.GetString("Server"))
|
||||||
|
err = errors.New(msg)
|
||||||
|
b.Log.Error(msg)
|
||||||
|
b.Log.Info("Possible values:")
|
||||||
|
for _, guild := range guilds {
|
||||||
|
b.Log.Infof("Server=\"%s\" # Server name", guild.Name)
|
||||||
|
b.Log.Infof("Server=\"%s\" # Server ID", guild.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -106,7 +120,7 @@ func (b *Bdiscord) Connect() error {
|
|||||||
defer b.membersMutex.Unlock()
|
defer b.membersMutex.Unlock()
|
||||||
members, err := b.c.GuildMembers(b.guildID, "", 1000)
|
members, err := b.c.GuildMembers(b.guildID, "", 1000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Log.Error("Error obtaining guild members", err)
|
b.Log.Error("Error obtaining server members: ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
@@ -176,8 +190,14 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
b.Log.Debugf("Broadcasting using Webhook")
|
b.Log.Debugf("Broadcasting using Webhook")
|
||||||
for _, f := range msg.Extra["file"] {
|
for _, f := range msg.Extra["file"] {
|
||||||
fi := f.(config.FileInfo)
|
fi := f.(config.FileInfo)
|
||||||
|
if fi.Comment != "" {
|
||||||
|
msg.Text += fi.Comment + ": "
|
||||||
|
}
|
||||||
if fi.URL != "" {
|
if fi.URL != "" {
|
||||||
msg.Text += " " + fi.URL
|
msg.Text = fi.URL
|
||||||
|
if fi.Comment != "" {
|
||||||
|
msg.Text = fi.Comment + ": " + fi.URL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// skip empty messages
|
// skip empty messages
|
||||||
|
|||||||
210
contrib/api.yaml
Normal file
210
contrib/api.yaml
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
openapi: 3.0.0
|
||||||
|
info:
|
||||||
|
contact: {}
|
||||||
|
description: A read/write API for the Matterbridge chat bridge.
|
||||||
|
license:
|
||||||
|
name: Apache 2.0
|
||||||
|
url: 'https://github.com/42wim/matterbridge/blob/master/LICENSE'
|
||||||
|
title: Matterbridge API
|
||||||
|
version: "0.1.0-oas3"
|
||||||
|
paths:
|
||||||
|
/health:
|
||||||
|
get:
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
'*/*':
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
summary: Checks if the server is alive.
|
||||||
|
/message:
|
||||||
|
post:
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/config.OutgoingMessageResponse'
|
||||||
|
summary: Create a message
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/config.OutgoingMessage'
|
||||||
|
description: Message object to create
|
||||||
|
required: true
|
||||||
|
/messages:
|
||||||
|
get:
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/config.IncomingMessage'
|
||||||
|
type: array
|
||||||
|
security:
|
||||||
|
- ApiKeyAuth: []
|
||||||
|
summary: List new messages
|
||||||
|
/stream:
|
||||||
|
get:
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/x-json-stream:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/config.IncomingMessage'
|
||||||
|
summary: Stream realtime messages
|
||||||
|
servers:
|
||||||
|
- url: /api
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
bearerAuth:
|
||||||
|
type: http
|
||||||
|
scheme: bearer
|
||||||
|
schemas:
|
||||||
|
config.IncomingMessage:
|
||||||
|
properties:
|
||||||
|
avatar:
|
||||||
|
description: URL to an avatar image
|
||||||
|
example: >-
|
||||||
|
https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg
|
||||||
|
type: string
|
||||||
|
event:
|
||||||
|
description: >-
|
||||||
|
A specific matterbridge event. (see
|
||||||
|
https://github.com/42wim/matterbridge/blob/master/bridge/config/config.go#L16)
|
||||||
|
type: string
|
||||||
|
gateway:
|
||||||
|
description: Name of the gateway as configured in matterbridge.toml
|
||||||
|
example: mygateway
|
||||||
|
type: string
|
||||||
|
text:
|
||||||
|
description: Content of the message
|
||||||
|
example: 'Testing, testing, 1-2-3.'
|
||||||
|
type: string
|
||||||
|
username:
|
||||||
|
description: Human-readable username
|
||||||
|
example: alice
|
||||||
|
type: string
|
||||||
|
account:
|
||||||
|
description: Unique account name of format "[protocol].[slug]" as defined in matterbridge.toml
|
||||||
|
example: slack.myteam
|
||||||
|
type: string
|
||||||
|
channel:
|
||||||
|
description: Human-readable channel name of sending bridge
|
||||||
|
example: test-channel
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
description: Unique ID of message on the gateway
|
||||||
|
example: slack 1541361213.030700
|
||||||
|
type: string
|
||||||
|
parent_id:
|
||||||
|
description: Unique ID of a parent message, if threaded
|
||||||
|
example: slack 1541361213.030700
|
||||||
|
type: string
|
||||||
|
protocol:
|
||||||
|
description: Chat protocol of the sending bridge
|
||||||
|
example: slack
|
||||||
|
type: string
|
||||||
|
timestamp:
|
||||||
|
description: Timestamp of the message
|
||||||
|
example: "1541361213.030700"
|
||||||
|
type: string
|
||||||
|
userid:
|
||||||
|
description: Userid on the sending bridge
|
||||||
|
example: U4MCXJKNC
|
||||||
|
type: string
|
||||||
|
extra:
|
||||||
|
description: Extra data that doesn't fit in other fields (eg base64 encoded files)
|
||||||
|
type: object
|
||||||
|
config.OutgoingMessage:
|
||||||
|
properties:
|
||||||
|
avatar:
|
||||||
|
description: URL to an avatar image
|
||||||
|
example: >-
|
||||||
|
https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg
|
||||||
|
type: string
|
||||||
|
event:
|
||||||
|
description: >-
|
||||||
|
A specific matterbridge event. (see
|
||||||
|
https://github.com/42wim/matterbridge/blob/master/bridge/config/config.go#L16)
|
||||||
|
example: ""
|
||||||
|
type: string
|
||||||
|
gateway:
|
||||||
|
description: Name of the gateway as configured in matterbridge.toml
|
||||||
|
example: mygateway
|
||||||
|
type: string
|
||||||
|
text:
|
||||||
|
description: Content of the message
|
||||||
|
example: 'Testing, testing, 1-2-3.'
|
||||||
|
type: string
|
||||||
|
username:
|
||||||
|
description: Human-readable username
|
||||||
|
example: alice
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- gateway
|
||||||
|
- text
|
||||||
|
- username
|
||||||
|
config.OutgoingMessageResponse:
|
||||||
|
properties:
|
||||||
|
avatar:
|
||||||
|
description: URL to an avatar image
|
||||||
|
example: >-
|
||||||
|
https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg
|
||||||
|
type: string
|
||||||
|
event:
|
||||||
|
description: >-
|
||||||
|
A specific matterbridge event. (see
|
||||||
|
https://github.com/42wim/matterbridge/blob/master/bridge/config/config.go#L16)
|
||||||
|
example: ""
|
||||||
|
type: string
|
||||||
|
gateway:
|
||||||
|
description: Name of the gateway as configured in matterbridge.toml
|
||||||
|
example: mygateway
|
||||||
|
type: string
|
||||||
|
text:
|
||||||
|
description: Content of the message
|
||||||
|
example: 'Testing, testing, 1-2-3.'
|
||||||
|
type: string
|
||||||
|
username:
|
||||||
|
description: Human-readable username
|
||||||
|
example: alice
|
||||||
|
type: string
|
||||||
|
account:
|
||||||
|
description: fixed api account
|
||||||
|
example: api.local
|
||||||
|
type: string
|
||||||
|
channel:
|
||||||
|
description: fixed api channel
|
||||||
|
example: api
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
example: ""
|
||||||
|
type: string
|
||||||
|
parent_id:
|
||||||
|
example: ""
|
||||||
|
type: string
|
||||||
|
protocol:
|
||||||
|
description: fixed api protocol
|
||||||
|
example: api
|
||||||
|
type: string
|
||||||
|
timestamp:
|
||||||
|
description: Timestamp of the message
|
||||||
|
example: "1541361213.030700"
|
||||||
|
type: string
|
||||||
|
userid:
|
||||||
|
example: ""
|
||||||
|
type: string
|
||||||
|
extra:
|
||||||
|
example: null
|
||||||
|
type: object
|
||||||
|
type: object
|
||||||
|
security:
|
||||||
|
- bearerAuth: []
|
||||||
Reference in New Issue
Block a user