diff --git a/README.md b/README.md index aab755a6..52f74f39 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,8 @@ * [API](https://github.com/42wim/matterbridge/wiki/Features#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. diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index a9c508c7..3cd5245c 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -2,6 +2,7 @@ package bdiscord import ( "bytes" + "errors" "fmt" "strings" "sync" @@ -49,6 +50,7 @@ func New(cfg *bridge.Config) bridge.Bridger { func (b *Bdiscord) Connect() error { var err error var token string + var guildFound bool b.Log.Info("Connecting") if b.GetString("WebhookURL") == "" { b.Log.Info("Connecting using token") @@ -86,12 +88,24 @@ func (b *Bdiscord) Connect() error { if guild.Name == serverName || guild.ID == serverName { b.channels, err = b.c.GuildChannels(guild.ID) b.guildID = guild.ID + guildFound = true if err != nil { break } } } 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 { return err } @@ -106,7 +120,7 @@ func (b *Bdiscord) Connect() error { defer b.membersMutex.Unlock() members, err := b.c.GuildMembers(b.guildID, "", 1000) if err != nil { - b.Log.Error("Error obtaining guild members", err) + b.Log.Error("Error obtaining server members: ", err) return err } for _, member := range members { @@ -176,8 +190,14 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { b.Log.Debugf("Broadcasting using Webhook") for _, f := range msg.Extra["file"] { fi := f.(config.FileInfo) + if fi.Comment != "" { + msg.Text += fi.Comment + ": " + } if fi.URL != "" { - msg.Text += " " + fi.URL + msg.Text = fi.URL + if fi.Comment != "" { + msg.Text = fi.Comment + ": " + fi.URL + } } } // skip empty messages diff --git a/contrib/api.yaml b/contrib/api.yaml new file mode 100644 index 00000000..328393f2 --- /dev/null +++ b/contrib/api.yaml @@ -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: []