github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/bot/service_helper.go (about) 1 package bot 2 3 import ( 4 "github.com/keybase/client/go/libkb" 5 "github.com/keybase/client/go/protocol/keybase1" 6 ) 7 8 func ListTokens(mctx libkb.MetaContext) (res []keybase1.BotTokenInfo, err error) { 9 type resType struct { 10 libkb.AppStatusEmbed 11 Tokens []keybase1.BotTokenInfo `json:"bot_tokens"` 12 } 13 var tmp resType 14 err = mctx.G().API.GetDecode(mctx, libkb.APIArg{ 15 Endpoint: "bot/token/list", 16 SessionType: libkb.APISessionTypeREQUIRED, 17 }, &tmp) 18 if err != nil { 19 return res, err 20 } 21 return tmp.Tokens, nil 22 } 23 24 func CreateToken(mctx libkb.MetaContext) (res keybase1.BotToken, err error) { 25 type resType struct { 26 libkb.AppStatusEmbed 27 Token keybase1.BotToken `json:"bot_token"` 28 } 29 var tmp resType 30 err = mctx.G().API.PostDecode(mctx, libkb.APIArg{ 31 Endpoint: "bot/token/create", 32 SessionType: libkb.APISessionTypeREQUIRED, 33 }, &tmp) 34 if err != nil { 35 return res, err 36 } 37 38 return tmp.Token, nil 39 } 40 41 func DeleteToken(mctx libkb.MetaContext, tok keybase1.BotToken) (err error) { 42 _, err = mctx.G().API.Post(mctx, libkb.APIArg{ 43 Endpoint: "bot/token/delete", 44 SessionType: libkb.APISessionTypeREQUIRED, 45 Args: libkb.HTTPArgs{ 46 "bot_token": libkb.S{Val: tok.String()}, 47 }, 48 }) 49 return err 50 }