Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use APIConvID #45

Merged
merged 6 commits into from Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -63,7 +63,7 @@ This must be run first in order to start the Keybase JSON API stdin/stdout inter

send a new message by specifying a channel

#### `API.SendMessageByConvID(convID string, body string) (SendResponse, error)`
#### `API.SendMessageByConvID(convID chat1.ConvIDStr, body string) (SendResponse, error)`

send a new message by specifying a conversation ID

Expand All @@ -90,7 +90,7 @@ to receive any new message across all conversations (except the bots own message

send a new message which can contain in-chat-send payments (i.e. `+5XLM@joshblum`) by specifying a channel

#### `API.InChatSendByConvID(convID string, body string) (SendResponse, error)`
#### `API.InChatSendByConvID(convID chat1.ConvIDStr, body string) (SendResponse, error)`

send a new message which can contain in-chat-send payments (i.e. `+5XLM@joshblum`) by specifying a conversation ID

Expand Down
28 changes: 14 additions & 14 deletions kbchat/chat.go
Expand Up @@ -25,7 +25,7 @@ type sendMessageBody struct {

type sendMessageOptions struct {
Channel chat1.ChatChannel `json:"channel,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
Message sendMessageBody `json:",omitempty"`
Filename string `json:"filename,omitempty"`
Title string `json:"title,omitempty"`
Expand Down Expand Up @@ -68,7 +68,7 @@ func (a *API) GetConversations(unreadOnly bool) ([]chat1.ConvSummary, error) {
return inbox.Result.Convs, nil
}

func (a *API) GetConversation(convID string) (res chat1.ConvSummary, err error) {
func (a *API) GetConversation(convID chat1.ConvIDStr) (res chat1.ConvSummary, err error) {
apiInput := fmt.Sprintf(`{"method":"list", "params": { "options": { "conversation_id": "%s"}}}`, convID)
output, err := a.doFetch(apiInput)
if err != nil {
Expand Down Expand Up @@ -134,7 +134,7 @@ func (a *API) Broadcast(body string, args ...interface{}) (SendResponse, error)
}, fmt.Sprintf(body, args...))
}

func (a *API) SendMessageByConvID(convID string, body string, args ...interface{}) (SendResponse, error) {
func (a *API) SendMessageByConvID(convID chat1.ConvIDStr, body string, args ...interface{}) (SendResponse, error) {
arg := newSendArg(sendMessageOptions{
ConversationID: convID,
Message: sendMessageBody{
Expand Down Expand Up @@ -197,7 +197,7 @@ func (a *API) SendAttachmentByTeam(teamName string, inChannel *string, filename
return a.doSend(arg)
}

func (a *API) SendAttachmentByConvID(convID string, filename string, title string) (SendResponse, error) {
func (a *API) SendAttachmentByConvID(convID chat1.ConvIDStr, filename string, title string) (SendResponse, error) {
arg := sendMessageArg{
Method: "attach",
Params: sendMessageParams{
Expand All @@ -216,7 +216,7 @@ func (a *API) SendAttachmentByConvID(convID string, filename string, title strin
////////////////////////////////////////////////////////

type reactionOptions struct {
ConversationID string `json:"conversation_id"`
ConversationID chat1.ConvIDStr `json:"conversation_id"`
Message sendMessageBody
MsgID chat1.MessageID `json:"message_id"`
Channel chat1.ChatChannel `json:"channel"`
Expand Down Expand Up @@ -247,7 +247,7 @@ func (a *API) ReactByChannel(channel chat1.ChatChannel, msgID chat1.MessageID, r
return a.doSend(arg)
}

func (a *API) ReactByConvID(convID string, msgID chat1.MessageID, reaction string) (SendResponse, error) {
func (a *API) ReactByConvID(convID chat1.ConvIDStr, msgID chat1.MessageID, reaction string) (SendResponse, error) {
arg := newReactionArg(reactionOptions{
Message: sendMessageBody{Body: reaction},
MsgID: msgID,
Expand All @@ -256,7 +256,7 @@ func (a *API) ReactByConvID(convID string, msgID chat1.MessageID, reaction strin
return a.doSend(arg)
}

func (a *API) EditByConvID(convID string, msgID chat1.MessageID, text string) (SendResponse, error) {
func (a *API) EditByConvID(convID chat1.ConvIDStr, msgID chat1.MessageID, text string) (SendResponse, error) {
arg := reactionArg{
Method: "edit",
Params: reactionParams{Options: reactionOptions{
Expand Down Expand Up @@ -363,7 +363,7 @@ func (a *API) InChatSend(channel chat1.ChatChannel, body string, args ...interfa
return a.doSend(arg)
}

func (a *API) InChatSendByConvID(convID string, body string, args ...interface{}) (SendResponse, error) {
func (a *API) InChatSendByConvID(convID chat1.ConvIDStr, body string, args ...interface{}) (SendResponse, error) {
arg := newSendArg(sendMessageOptions{
ConversationID: convID,
Message: sendMessageBody{
Expand Down Expand Up @@ -436,8 +436,8 @@ func (a *API) ClearCommands() error {
}

type listCmdsOptions struct {
Channel chat1.ChatChannel
ConversationID string
Channel chat1.ChatChannel `json:"channel,omitempty"`
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
}

type listCmdsParams struct {
Expand Down Expand Up @@ -465,9 +465,9 @@ func (a *API) ListCommands(channel chat1.ChatChannel) ([]chat1.UserBotCommandOut
return a.listCommands(arg)
}

func (a *API) ListCommandsByConvID(conversationID string) ([]chat1.UserBotCommandOutput, error) {
func (a *API) ListCommandsByConvID(convID chat1.ConvIDStr) ([]chat1.UserBotCommandOutput, error) {
arg := newListCmdsArg(listCmdsOptions{
ConversationID: conversationID,
ConversationID: convID,
})
return a.listCommands(arg)
}
Expand All @@ -492,7 +492,7 @@ func (a *API) listCommands(arg listCmdsArg) ([]chat1.UserBotCommandOutput, error

type listMembersOptions struct {
Channel chat1.ChatChannel `json:"channel,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
}

type listMembersParams struct {
Expand Down Expand Up @@ -520,7 +520,7 @@ func (a *API) ListMembers(channel chat1.ChatChannel) (keybase1.TeamMembersDetail
return a.listMembers(arg)
}

func (a *API) ListMembersByConvID(conversationID string) (keybase1.TeamMembersDetails, error) {
func (a *API) ListMembersByConvID(conversationID chat1.ConvIDStr) (keybase1.TeamMembersDetails, error) {
arg := newListMembersArg(listMembersOptions{
ConversationID: conversationID,
})
Expand Down
2 changes: 1 addition & 1 deletion kbchat/kbchat_test.go
Expand Up @@ -75,7 +75,7 @@ func getMostRecentMessage(t *testing.T, bot *API, channel chat1.ChatChannel) cha
return messages[0]
}

func getConvIDForChannel(t *testing.T, bot *API, channel chat1.ChatChannel) string {
func getConvIDForChannel(t *testing.T, bot *API, channel chat1.ChatChannel) chat1.ConvIDStr {
messages, err := bot.GetTextMessages(channel, false)
require.NoError(t, err)
convID := messages[0].ConvID
Expand Down
88 changes: 53 additions & 35 deletions kbchat/types/chat1/api.go
Expand Up @@ -8,6 +8,24 @@ import (
keybase1 "github.com/keybase/go-keybase-chat-bot/kbchat/types/keybase1"
)

type ConvIDStr string

func (o ConvIDStr) DeepCopy() ConvIDStr {
return o
}

type TLFIDStr string

func (o TLFIDStr) DeepCopy() TLFIDStr {
return o
}

type FlipGameIDStr string

func (o FlipGameIDStr) DeepCopy() FlipGameIDStr {
return o
}

type RateLimitRes struct {
Tank string `codec:"tank" json:"tank"`
Capacity int `codec:"capacity" json:"capacity"`
Expand Down Expand Up @@ -56,46 +74,46 @@ func (o ChatMessage) DeepCopy() ChatMessage {
}

type MsgSender struct {
Uid string `codec:"uid" json:"uid"`
Username string `codec:"username,omitempty" json:"username,omitempty"`
DeviceID string `codec:"deviceID" json:"device_id"`
DeviceName string `codec:"deviceName,omitempty" json:"device_name,omitempty"`
Uid keybase1.UID `codec:"uid" json:"uid"`
Username string `codec:"username,omitempty" json:"username,omitempty"`
DeviceID keybase1.DeviceID `codec:"deviceID" json:"device_id"`
DeviceName string `codec:"deviceName,omitempty" json:"device_name,omitempty"`
}

func (o MsgSender) DeepCopy() MsgSender {
return MsgSender{
Uid: o.Uid,
Uid: o.Uid.DeepCopy(),
Username: o.Username,
DeviceID: o.DeviceID,
DeviceID: o.DeviceID.DeepCopy(),
DeviceName: o.DeviceName,
}
}

type MsgBotInfo struct {
BotUID string `codec:"botUID" json:"bot_uid"`
BotUsername string `codec:"botUsername,omitempty" json:"bot_username,omitempty"`
BotUID keybase1.UID `codec:"botUID" json:"bot_uid"`
BotUsername string `codec:"botUsername,omitempty" json:"bot_username,omitempty"`
}

func (o MsgBotInfo) DeepCopy() MsgBotInfo {
return MsgBotInfo{
BotUID: o.BotUID,
BotUID: o.BotUID.DeepCopy(),
BotUsername: o.BotUsername,
}
}

type MsgFlipContent struct {
Text string `codec:"text" json:"text"`
GameID string `codec:"gameID" json:"game_id"`
FlipConvID string `codec:"flipConvID" json:"flip_conv_id"`
GameID FlipGameIDStr `codec:"gameID" json:"game_id"`
FlipConvID ConvIDStr `codec:"flipConvID" json:"flip_conv_id"`
UserMentions []KnownUserMention `codec:"userMentions" json:"user_mentions"`
TeamMentions []KnownTeamMention `codec:"teamMentions" json:"team_mentions"`
}

func (o MsgFlipContent) DeepCopy() MsgFlipContent {
return MsgFlipContent{
Text: o.Text,
GameID: o.GameID,
FlipConvID: o.FlipConvID,
GameID: o.GameID.DeepCopy(),
FlipConvID: o.FlipConvID.DeepCopy(),
UserMentions: (func(x []KnownUserMention) []KnownUserMention {
if x == nil {
return nil
Expand Down Expand Up @@ -237,7 +255,7 @@ func (o MsgContent) DeepCopy() MsgContent {

type MsgSummary struct {
Id MessageID `codec:"id" json:"id"`
ConvID string `codec:"convID" json:"conversation_id"`
ConvID ConvIDStr `codec:"convID" json:"conversation_id"`
Channel ChatChannel `codec:"channel" json:"channel"`
Sender MsgSender `codec:"sender" json:"sender"`
SentAt int64 `codec:"sentAt" json:"sent_at"`
Expand All @@ -262,7 +280,7 @@ type MsgSummary struct {
func (o MsgSummary) DeepCopy() MsgSummary {
return MsgSummary{
Id: o.Id.DeepCopy(),
ConvID: o.ConvID,
ConvID: o.ConvID.DeepCopy(),
Channel: o.Channel.DeepCopy(),
Sender: o.Sender.DeepCopy(),
SentAt: o.SentAt,
Expand Down Expand Up @@ -407,7 +425,7 @@ func (o Thread) DeepCopy() Thread {

// A chat conversation. This is essentially a chat channel plus some additional metadata.
type ConvSummary struct {
Id string `codec:"id" json:"id"`
Id ConvIDStr `codec:"id" json:"id"`
Channel ChatChannel `codec:"channel" json:"channel"`
IsDefaultConv bool `codec:"isDefaultConv" json:"is_default_conv"`
Unread bool `codec:"unread" json:"unread"`
Expand All @@ -416,14 +434,14 @@ type ConvSummary struct {
MemberStatus string `codec:"memberStatus" json:"member_status"`
ResetUsers []string `codec:"resetUsers,omitempty" json:"reset_users,omitempty"`
FinalizeInfo *ConversationFinalizeInfo `codec:"finalizeInfo,omitempty" json:"finalize_info,omitempty"`
Supersedes []string `codec:"supersedes,omitempty" json:"supersedes,omitempty"`
SupersededBy []string `codec:"supersededBy,omitempty" json:"superseded_by,omitempty"`
Supersedes []ConvIDStr `codec:"supersedes,omitempty" json:"supersedes,omitempty"`
SupersededBy []ConvIDStr `codec:"supersededBy,omitempty" json:"superseded_by,omitempty"`
Error string `codec:"error,omitempty" json:"error,omitempty"`
}

func (o ConvSummary) DeepCopy() ConvSummary {
return ConvSummary{
Id: o.Id,
Id: o.Id.DeepCopy(),
Channel: o.Channel.DeepCopy(),
IsDefaultConv: o.IsDefaultConv,
Unread: o.Unread,
Expand All @@ -448,24 +466,24 @@ func (o ConvSummary) DeepCopy() ConvSummary {
tmp := (*x).DeepCopy()
return &tmp
})(o.FinalizeInfo),
Supersedes: (func(x []string) []string {
Supersedes: (func(x []ConvIDStr) []ConvIDStr {
if x == nil {
return nil
}
ret := make([]string, len(x))
ret := make([]ConvIDStr, len(x))
for i, v := range x {
vCopy := v
vCopy := v.DeepCopy()
ret[i] = vCopy
}
return ret
})(o.Supersedes),
SupersededBy: (func(x []string) []string {
SupersededBy: (func(x []ConvIDStr) []ConvIDStr {
if x == nil {
return nil
}
ret := make([]string, len(x))
ret := make([]ConvIDStr, len(x))
for i, v := range x {
vCopy := v
vCopy := v.DeepCopy()
ret[i] = vCopy
}
return ret
Expand Down Expand Up @@ -655,14 +673,14 @@ func (o RegexpRes) DeepCopy() RegexpRes {
}

type NewConvRes struct {
Id string `codec:"id" json:"id"`
Id ConvIDStr `codec:"id" json:"id"`
IdentifyFailures []keybase1.TLFIdentifyFailure `codec:"identifyFailures,omitempty" json:"identify_failures,omitempty"`
RateLimits []RateLimitRes `codec:"rateLimits,omitempty" json:"ratelimits,omitempty"`
}

func (o NewConvRes) DeepCopy() NewConvRes {
return NewConvRes{
Id: o.Id,
Id: o.Id.DeepCopy(),
IdentifyFailures: (func(x []keybase1.TLFIdentifyFailure) []keybase1.TLFIdentifyFailure {
if x == nil {
return nil
Expand Down Expand Up @@ -827,13 +845,13 @@ func (o AdvertiseCommandAPIParam) DeepCopy() AdvertiseCommandAPIParam {
}

type ResetConvMemberAPI struct {
ConversationID string `codec:"conversationID" json:"conversationID"`
Username string `codec:"username" json:"username"`
ConversationID ConvIDStr `codec:"conversationID" json:"conversationID"`
Username string `codec:"username" json:"username"`
}

func (o ResetConvMemberAPI) DeepCopy() ResetConvMemberAPI {
return ResetConvMemberAPI{
ConversationID: o.ConversationID,
ConversationID: o.ConversationID.DeepCopy(),
Username: o.Username,
}
}
Expand Down Expand Up @@ -871,15 +889,15 @@ func (o GetResetConvMembersRes) DeepCopy() GetResetConvMembersRes {
}

type DeviceInfo struct {
DeviceID string `codec:"deviceID" json:"id"`
DeviceDescription string `codec:"deviceDescription" json:"description"`
DeviceType string `codec:"deviceType" json:"type"`
DeviceCtime int64 `codec:"deviceCtime" json:"ctime"`
DeviceID keybase1.DeviceID `codec:"deviceID" json:"id"`
DeviceDescription string `codec:"deviceDescription" json:"description"`
DeviceType string `codec:"deviceType" json:"type"`
DeviceCtime int64 `codec:"deviceCtime" json:"ctime"`
}

func (o DeviceInfo) DeepCopy() DeviceInfo {
return DeviceInfo{
DeviceID: o.DeviceID,
DeviceID: o.DeviceID.DeepCopy(),
DeviceDescription: o.DeviceDescription,
DeviceType: o.DeviceType,
DeviceCtime: o.DeviceCtime,
Expand Down