Give api access to whole config.Message (and events). Closes #374

This commit is contained in:
Wim 2018-02-20 18:36:44 +01:00
parent a2b94452db
commit f2efc06d1f

View File

@ -76,21 +76,18 @@ func (b *Api) Send(msg config.Message) (string, error) {
} }
func (b *Api) handlePostMessage(c echo.Context) error { func (b *Api) handlePostMessage(c echo.Context) error {
message := &ApiMessage{} message := config.Message{}
if err := c.Bind(message); err != nil { if err := c.Bind(&message); err != nil {
return err return err
} }
// these values are fixed
message.Channel = "api"
message.Protocol = "api"
message.Account = b.Account
message.ID = ""
message.Timestamp = time.Now()
flog.Debugf("Sending message from %s on %s to gateway", message.Username, "api") flog.Debugf("Sending message from %s on %s to gateway", message.Username, "api")
b.Remote <- config.Message{ b.Remote <- message
Text: message.Text,
Username: message.Username,
UserID: message.UserID,
Channel: "api",
Avatar: message.Avatar,
Account: b.Account,
Gateway: message.Gateway,
Protocol: "api",
}
return c.JSON(http.StatusOK, message) return c.JSON(http.StatusOK, message)
} }