Add bot advertisement methods
This commit is contained in:
38
chat.go
38
chat.go
@ -489,3 +489,41 @@ func (c Chat) Mark(messageID int) (ChatAPI, error) {
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// ClearCommands clears bot advertisements
|
||||
func (k *Keybase) ClearCommands() (ChatAPI, error) {
|
||||
m := ChatAPI{}
|
||||
m.Method = "clearcommands"
|
||||
|
||||
r, err := chatAPIOut(k, m)
|
||||
if err != nil {
|
||||
return ChatAPI{}, err
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// AdvertiseCommands sets up bot command advertisements
|
||||
// This method allows you to set up multiple different types of advertisements at once.
|
||||
// Use this method if you have commands whose visibility differs from each other.
|
||||
func (k *Keybase) AdvertiseCommands(advertisements []BotAdvertisement) (ChatAPI, error) {
|
||||
m := ChatAPI{
|
||||
Params: ¶ms{},
|
||||
}
|
||||
m.Method = "advertisecommands"
|
||||
m.Params.Options.BotAdvertisements = advertisements
|
||||
|
||||
r, err := chatAPIOut(k, m)
|
||||
if err != nil {
|
||||
return ChatAPI{}, err
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// AdvertiseCommand sets up bot command advertisements
|
||||
// This method allows you to set up one type of advertisement.
|
||||
// Use this method if you have commands whose visibility should all be the same.
|
||||
func (k *Keybase) AdvertiseCommand(advertisement BotAdvertisement) (ChatAPI, error) {
|
||||
return k.AdvertiseCommands([]BotAdvertisement{
|
||||
advertisement,
|
||||
})
|
||||
}
|
||||
|
||||
@ -36,6 +36,14 @@ func NewKeybase(path ...string) *Keybase {
|
||||
return k
|
||||
}
|
||||
|
||||
// NewBotCommand returns a new BotCommand instance
|
||||
func NewBotCommand(name string, description string) BotCommand {
|
||||
return BotCommand{
|
||||
Name: name,
|
||||
Description: description,
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the given Keybase command
|
||||
func (k *Keybase) Exec(command ...string) ([]byte, error) {
|
||||
out, err := exec.Command(k.Path, command...).Output()
|
||||
|
||||
18
types.go
18
types.go
@ -296,6 +296,17 @@ type Channel struct {
|
||||
TopicName string `json:"topic_name,omitempty"`
|
||||
}
|
||||
|
||||
type BotCommand struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type BotAdvertisement struct {
|
||||
Type string `json:"type"` // "public", "teamconvs", "teammembers"
|
||||
TeamName string `json:"team_name,omitempty"` // required if Type is not "public"
|
||||
BotCommands []BotCommand `json:"commands"`
|
||||
}
|
||||
|
||||
type mesg struct {
|
||||
Body string `json:"body"`
|
||||
}
|
||||
@ -313,6 +324,8 @@ type options struct {
|
||||
MsgID int `json:"msg_id,omitempty"`
|
||||
ReplyTo int `json:"reply_to,omitempty"`
|
||||
GameID string `json:"game_id,omitempty"`
|
||||
Alias string `json:"alias,omitempty"`
|
||||
BotAdvertisements []BotAdvertisement `json:"advertisements,omitempty"`
|
||||
|
||||
Name string `json:"name,omitempty"`
|
||||
Public bool `json:"public,omitempty"`
|
||||
@ -641,14 +654,17 @@ type wallet interface {
|
||||
}
|
||||
|
||||
type keybase interface {
|
||||
AdvertiseCommand(advertisement BotAdvertisement) (ChatAPI, error)
|
||||
AdvertiseCommands(advertisements []BotAdvertisement) (ChatAPI, error)
|
||||
ChatList() (ChatAPI, error)
|
||||
ClearCommands() (ChatAPI, error)
|
||||
CreateTeam(name string) (TeamAPI, error)
|
||||
NewChat(channel Channel) Chat
|
||||
NewTeam(name string) Team
|
||||
NewWallet() Wallet
|
||||
Run(handler func(ChatAPI), options ...RunOptions)
|
||||
version() string
|
||||
status() status
|
||||
version() string
|
||||
}
|
||||
|
||||
type status struct {
|
||||
|
||||
Reference in New Issue
Block a user