diff --git a/api/api.go b/api/api.go index f81903d..953d80f 100644 --- a/api/api.go +++ b/api/api.go @@ -11,9 +11,9 @@ type Keybase struct { } type keybase interface { - ChatSend(user, message string) (chatOutResult, error) - ChatSendTeam(team, channel, message string) (chatOutResult, error) - ChatList() (chatOutResult, error) + ChatSendText(user string, message ...string) (chatOutResultResult, error) + ChatSendTextTeam(team, channel, message string) (chatOutResultResult, error) + ChatList() ([]chatOutResultConversations, error) LoggedIn() bool Username() string Version() string diff --git a/api/chatOut.go b/api/chatOut.go index 0113095..12c4d50 100644 --- a/api/chatOut.go +++ b/api/chatOut.go @@ -3,6 +3,7 @@ package api import ( "encoding/json" "os/exec" + "strings" ) // ---- Struct for sending to API @@ -80,25 +81,33 @@ func chatAPIOut(keybasePath string, c chatOut) (chatOutResult, error) { } // ChatSend() sends a chat message to a user. -func (k Keybase) ChatSend(user, message string) (chatOutResult, error) { +func (k Keybase) ChatSendText(user string, message ...string) (chatOutResultResult, error) { m := chatOut{} m.Method = "send" m.Params.Options.Channel.Name = user - m.Params.Options.Message.Body = message + m.Params.Options.Message.Body = strings.Join(message, " ") - return chatAPIOut(k.path, m) + r, err := chatAPIOut(k.path, m) + if err != nil { + return chatOutResultResult{}, err + } + return r.Result, nil } // ChatSendTeam() sends a chat message to a team. -func (k Keybase) ChatSendTeam(team, channel, message string) (chatOutResult, error) { +func (k Keybase) ChatSendTextTeam(team, channel string, message ...string) (chatOutResultResult, error) { m := chatOut{} m.Method = "send" m.Params.Options.Channel.Name = team m.Params.Options.Channel.MembersType = "team" m.Params.Options.Channel.TopicName = channel - m.Params.Options.Message.Body = message + m.Params.Options.Message.Body = strings.Join(message, " ") - return chatAPIOut(k.path, m) + r, err := chatAPIOut(k.path, m) + if err != nil { + return chatOutResultResult{}, err + } + return r.Result, nil } // ChatList() returns a list of all conversations. diff --git a/main.go b/main.go index 6cdfc29..a60ca6e 100644 --- a/main.go +++ b/main.go @@ -26,8 +26,8 @@ func main() { allChats += fmt.Sprintf("%s\n", chat.Channel.Name) } } - c, _ := k.ChatSend(username, fmt.Sprintf("Version: %s\nConversations:\n```%s```\n", version, allChats)) - fmt.Println(c.Result.Message) + c, _ := k.ChatSendText(username, fmt.Sprintf("Version: %s\nConversations:\n```%s```\n", version, allChats)) + fmt.Println(c.Message, "-", c.ID) } else { fmt.Println("Not logged in") }