keybase: samhofi.us/x/keybase Index | Examples | Files

package keybase

import "samhofi.us/x/keybase"

The keybase package implements an interface for interacting with the Keybase Chat, Team, and Wallet APIs

I've tried to follow Keybase's JSON API as closely as possible, so if you're stuck on anything, or wondering why things are organized in a certain way, it's most likely due to that. It may be helpful to look at the Keybase JSON API docs by running some of the following commands in your terminal:

// Chat API
keybase chat api -h

// Chat Message Stream
keybase chat api-listen -h

// Team API
keybase team api -h

// Wallet API
keybase wallet api -h

The git repo for this code is hosted on Keybase. You can contact me directly (https://keybase.io/dxb), or join the mkbot team (https://keybase.io/team/mkbot) if you need assistance, or if you'd like to contribute.

Basic Example

Here's a quick example of a bot that will attach a reaction with the sender's device name to every message sent in @mkbot#test1:

package main

import (
	"fmt"

	"samhofi.us/x/keybase"
)

var k = keybase.NewKeybase()

func main() {
	channel := keybase.Channel{
		Name:        "mkbot",
		TopicName:   "test1",
		MembersType: keybase.TEAM,
	}
	opts := keybase.RunOptions{
		FilterChannel: channel,
	}
	fmt.Println("Running...")
	k.Run(handler, opts)
}

func handler(m keybase.ChatAPI) {
	msgType := m.Msg.Content.Type
	msgID := m.Msg.ID
	deviceName := m.Msg.Sender.DeviceName

	if msgType == "text" {
		chat := k.NewChat(m.Msg.Channel)
		chat.React(msgID, deviceName)
	}
}

Index

Examples

Package Files

chat.go docs.go keybase.go team.go types.go wallet.go

Constants

const (
    TEAM string = "team"
    USER string = "impteamnative"
)

Possible MemberTypes

const (
    DEV  string = "dev"
    CHAT string = "chat"
)

Possible TopicTypes

type BotAdvertisement Uses

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 BotCommand Uses

type BotCommand struct {
    Name                string                         `json:"name"`
    Description         string                         `json:"description"`
    Usage               string                         `json:"usage"`
    ExtendedDescription *BotCommandExtendedDescription `json:"extended_description,omitempty"`
}

func NewBotCommand Uses

func NewBotCommand(name, description, usage string, extendedDescription ...BotCommandExtendedDescription) BotCommand

NewBotCommand returns a new BotCommand instance

type BotCommandExtendedDescription Uses

type BotCommandExtendedDescription struct {
    Title       string `json:"title"`
    DesktopBody string `json:"desktop_body"`
    MobileBody  string `json:"mobile_body"`
}

func NewBotCommandExtendedDescription Uses

func NewBotCommandExtendedDescription(title, desktopBody, mobileBody string) BotCommandExtendedDescription

NewBotCommandExtendedDescription

type Channel Uses

type Channel struct {
    Name        string `json:"name,omitempty"`
    Public      bool   `json:"public,omitempty"`
    MembersType string `json:"members_type,omitempty"`
    TopicType   string `json:"topic_type,omitempty"`
    TopicName   string `json:"topic_name,omitempty"`
}

Channel holds information about a conversation

type Chat Uses

type Chat struct {
    Channel Channel
    // contains filtered or unexported fields
}

Chat holds basic information about a specific conversation

func (Chat) Delete Uses

func (c Chat) Delete(messageID int) (ChatAPI, error)

Delete deletes a chat message

func (Chat) Download Uses

func (c Chat) Download(messageID int, filepath string) (ChatAPI, error)

Download downloads a file from a conversation

func (Chat) Edit Uses

func (c Chat) Edit(messageID int, message ...string) (ChatAPI, error)

Edit edits a previously sent chat message

func (Chat) LoadFlip Uses

func (c Chat) LoadFlip(messageID int, conversationID string, flipConversationID string, gameID string) (ChatAPI, error)

LoadFlip returns the results of a flip If the flip is still in progress, this can be expected to change if called again

func (Chat) Mark Uses

func (c Chat) Mark(messageID int) (ChatAPI, error)

Mark marks a conversation as read up to a specified message

func (Chat) Pin Uses

func (c Chat) Pin(messageID int) (ChatAPI, error)

Pin pins a message to a channel

func (Chat) React Uses

func (c Chat) React(messageID int, reaction string) (ChatAPI, error)

React sends a reaction to a message.

func (Chat) Read Uses

func (c Chat) Read(count ...int) (*ChatAPI, error)

Read fetches chat messages from a conversation. By default, 10 messages will be fetched at a time. However, if count is passed, then that is the number of messages that will be fetched.

func (Chat) ReadMessage Uses

func (c Chat) ReadMessage(messageID int) (*ChatAPI, error)

ReadMessage fetches the chat message with the specified message id from a conversation.

func (Chat) Reply Uses

func (c Chat) Reply(replyTo int, message ...string) (ChatAPI, error)

Reply sends a reply to a chat message

func (Chat) Send Uses

func (c Chat) Send(message ...string) (ChatAPI, error)

Send sends a chat message

func (Chat) Unpin Uses

func (c Chat) Unpin() (ChatAPI, error)

Unpin clears any pinned messages from a channel

func (Chat) Upload Uses

func (c Chat) Upload(title string, filepath string) (ChatAPI, error)

Upload attaches a file to a conversation The filepath must be an absolute path

type ChatAPI Uses

type ChatAPI struct {
    Type         string        `json:"type,omitempty"`
    Source       string        `json:"source,omitempty"`
    Msg          *msg          `json:"msg,omitempty"`
    Method       string        `json:"method,omitempty"`
    Params       *params       `json:"params,omitempty"`
    Message      string        `json:"message,omitempty"`
    ID           int           `json:"id,omitempty"`
    Ratelimits   []rateLimits  `json:"ratelimits,omitempty"`
    Notification *notification `json:"notification,omitempty"`
    Result       *result       `json:"result,omitempty"`
    Pagination   *pagination   `json:"pagination,omitempty"`
    Error        *Error        `json:"error,omitempty"`
    // contains filtered or unexported fields
}

ChatAPI holds information about a message received by the `keybase chat api-listen` command

func (*ChatAPI) Next Uses

func (c *ChatAPI) Next(count ...int) (*ChatAPI, error)

Next fetches the next page of chat messages that were fetched with Read. By default, Next will fetch the same amount of messages that were originally fetched with Read. However, if count is passed, then that is the number of messages that will be fetched.

func (*ChatAPI) Previous Uses

func (c *ChatAPI) Previous(count ...int) (*ChatAPI, error)

Previous fetches the previous page of chat messages that were fetched with Read. By default, Previous will fetch the same amount of messages that were originally fetched with Read. However, if count is passed, then that is the number of messages that will be fetched.

type Error Uses

type Error struct {
    Code    int    `json:"code"`
    Message string `json:"message"`
}

type Keybase Uses

type Keybase struct {
    Path     string
    Username string
    LoggedIn bool
    Version  string
    Device   string
}

Keybase holds basic information about the local Keybase executable

func NewKeybase Uses

func NewKeybase(path ...string) *Keybase

NewKeybase returns a new Keybase. Optionally, you can pass a string containing the path to the Keybase executable as the first argument.

func (*Keybase) AdvertiseCommand Uses

func (k *Keybase) AdvertiseCommand(advertisement BotAdvertisement) (ChatAPI, error)

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.

Code:

var k = NewKeybase()

// Clear out any previously advertised commands
k.ClearCommands()

// Create BotAdvertisement
c := BotAdvertisement{
    Type: "public",
    BotCommands: []BotCommand{
        NewBotCommand("help", "Get help using this bot", "!help <command>"),
        NewBotCommand("hello", "Say hello", "!hello"),
    },
}

// Send advertisement
k.AdvertiseCommand(c)

func (*Keybase) AdvertiseCommands Uses

func (k *Keybase) AdvertiseCommands(advertisements []BotAdvertisement) (ChatAPI, error)

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 (*Keybase) ChatList Uses

func (k *Keybase) ChatList(opts ...Channel) (ChatAPI, error)

ChatList returns a list of all conversations. You can pass a Channel to use as a filter here, but you'll probably want to leave the TopicName empty.

func (*Keybase) ClearCommands Uses

func (k *Keybase) ClearCommands() (ChatAPI, error)

ClearCommands clears bot advertisements

func (*Keybase) CreateTeam Uses

func (k *Keybase) CreateTeam(name string) (TeamAPI, error)

CreateTeam creates a new team

func (*Keybase) Exec Uses

func (k *Keybase) Exec(command ...string) ([]byte, error)

Exec executes the given Keybase command

func (*Keybase) NewChat Uses

func (k *Keybase) NewChat(channel Channel) Chat

NewChat returns a new Chat instance

func (*Keybase) NewTeam Uses

func (k *Keybase) NewTeam(name string) Team

NewTeam returns a new Team instance

func (*Keybase) NewWallet Uses

func (k *Keybase) NewWallet() Wallet

NewWallet returns a new Wallet instance

func (*Keybase) Run Uses

func (k *Keybase) Run(handler func(ChatAPI), options ...RunOptions)

Run runs `keybase chat api-listen`, and passes incoming messages to the message handler func

type RequestPayment Uses

type RequestPayment struct {
    RequestID string `json:"requestID"`
    Note      string `json:"note"`
}

type RunOptions Uses

type RunOptions struct {
    Capacity       int       // Channel capacity for the buffered channel that holds messages. Defaults to 100 if not set
    Heartbeat      int64     // Send a heartbeat through the channel every X minutes (0 = off)
    Local          bool      // Subscribe to local messages
    HideExploding  bool      // Ignore exploding messages
    Dev            bool      // Subscribe to dev channel messages
    Wallet         bool      // Subscribe to wallet events
    FilterChannel  Channel   // Only subscribe to messages from specified channel
    FilterChannels []Channel // Only subscribe to messages from specified channels
}

RunOptions holds a set of options to be passed to Run

type SendPayment Uses

type SendPayment struct {
    PaymentID string `json:"paymentID"`
}

type Team Uses

type Team struct {
    Name string
    // contains filtered or unexported fields
}

Team holds basic information about a team

func (Team) AddAdmins Uses

func (t Team) AddAdmins(users ...string) (TeamAPI, error)

AddAdmins adds members to a team by username, and sets their roles to Writer

func (Team) AddOwners Uses

func (t Team) AddOwners(users ...string) (TeamAPI, error)

AddOwners adds members to a team by username, and sets their roles to Writer

func (Team) AddReaders Uses

func (t Team) AddReaders(users ...string) (TeamAPI, error)

AddReaders adds members to a team by username, and sets their roles to Reader

func (Team) AddUser Uses

func (t Team) AddUser(user, role string) (TeamAPI, error)

AddUser adds a member to a team by username

func (Team) AddWriters Uses

func (t Team) AddWriters(users ...string) (TeamAPI, error)

AddWriters adds members to a team by username, and sets their roles to Writer

func (Team) CreateSubteam Uses

func (t Team) CreateSubteam(name string) (TeamAPI, error)

CreateSubteam creates a subteam

func (Team) MemberList Uses

func (t Team) MemberList() (TeamAPI, error)

MemberList returns a list of a team's members

func (Team) RemoveUser Uses

func (t Team) RemoveUser(user string) (TeamAPI, error)

RemoveUser removes a member from a team

type TeamAPI Uses

type TeamAPI struct {
    Method string   `json:"method,omitempty"`
    Params *tParams `json:"params,omitempty"`
    Result *tResult `json:"result,omitempty"`
    Error  *Error   `json:"error"`
}

TeamAPI holds information sent and received to/from the team api

type Wallet Uses

type Wallet struct {
    // contains filtered or unexported fields
}

Wallet holds basic information about a wallet

func (Wallet) CancelRequest Uses

func (w Wallet) CancelRequest(requestID string) error

CancelRequest cancels a request for payment previously sent to a user

func (Wallet) RequestPayment Uses

func (w Wallet) RequestPayment(user string, amount float64, memo ...string) error

RequestPayment sends a request for payment to a user

func (Wallet) Send Uses

func (w Wallet) Send(recipient string, amount string, currency string, message ...string) (WalletAPI, error)

Send sends the specified amount of the specified currency to a user

func (Wallet) SendXLM Uses

func (w Wallet) SendXLM(recipient string, amount string, message ...string) (WalletAPI, error)

SendXLM sends the specified amount of XLM to a user

func (Wallet) StellarAddress Uses

func (w Wallet) StellarAddress(user string) (string, error)

StellarAddress returns the primary stellar address of a given user

func (Wallet) TxDetail Uses

func (w Wallet) TxDetail(txid string) (WalletAPI, error)

TxDetail returns details of a stellar transaction

type WalletAPI Uses

type WalletAPI struct {
    Method string   `json:"method,omitempty"`
    Params *wParams `json:"params,omitempty"`
    Result *wResult `json:"result,omitempty"`
    Error  *Error   `json:"error"`
}

WalletAPI holds data for sending to API

Package keybase imports 9 packages (graph) and is imported by 1 packages. Updated 2019-11-04. Refresh now. Tools for package owners.