keybase

package module
v2.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2021 License: MIT Imports: 10 Imported by: 6

Documentation

Overview

Package keybase 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) {
	if m.ErrorListen != nil {
		fmt.Printf("Error: %s\n", *m.ErrorListen)
		return
	}

    	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

Constants

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

Possible MemberTypes

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

Possible TopicTypes

Variables

This section is empty.

Functions

This section is empty.

Types

type AdvertiseCommandsOptions

type AdvertiseCommandsOptions struct {
	Alias          string
	Advertisements []chat1.AdvertiseCommandAPIParam
}

AdvertiseCommandsOptions holds a set of options to be passed to AdvertiseCommands

type Chat

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

Chat holds basic information about a specific conversation

func (Chat) LoadFlip

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

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

Mark marks a conversation as read up to a specified message

func (Chat) Pin

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

Pin pins a message to a channel

func (Chat) Unpin

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

Unpin clears any pinned messages from a channel

type ChatAPI

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"`
	ErrorRaw     *json.RawMessage `json:"error,omitempty"` // Raw JSON string containing any errors returned
	ErrorRead    *Error           `json:"-"`               // Errors returned by any outgoing chat functions such as Read(), Edit(), etc
	ErrorListen  *string          `json:"-"`               // Errors returned by the api-listen command (used in the Run() function)
	// contains filtered or unexported fields
}

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

type DownloadOptions

type DownloadOptions struct {
	Channel        chat1.ChatChannel
	ConversationID chat1.ConvIDStr `json:"conversation_id"`
	MessageID      chat1.MessageID `json:"message_id"`
	Output         string
	Preview        bool
	NoStream       bool
}

DownloadOptions holds a set of options to be passed to Download

type Error

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

Error holds an error message returned by the API

type ExplodingLifetime

type ExplodingLifetime struct {
	time.Duration
}

ExplodingLifetime holds a time duration for ephemeral messages

func (*ExplodingLifetime) MarshalJSON

func (d *ExplodingLifetime) MarshalJSON() (b []byte, err error)

MarshalJSON packs exploding lifetimes to JSON

func (*ExplodingLifetime) UnmarshalJSON

func (d *ExplodingLifetime) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unpacks exploding lifetimes from JSON

type Handlers

type Handlers struct {
	ChatHandler         *func(chat1.MsgSummary)
	ConversationHandler *func(chat1.ConvSummary)
	WalletHandler       *func(stellar1.PaymentDetailsLocal)
	ErrorHandler        *func(error)
}

Handlers holds pointers to handlers that you want to implement inside the bot type

type KVOptions

type KVOptions struct {
	Team       *string `json:"team"`
	Namespace  *string `json:"namespace,omitempty"`
	EntryKey   *string `json:"entryKey,omitempty"`
	EntryValue *string `json:"entryValue,omitempty"`
	Revision   *int    `json:"revision,omitempty"`
}

KVOptions holds a set of options to be passed to the KV methods

type Keybase

type Keybase struct {
	HomePath string
	ExePath  string
	Username string
	LoggedIn bool
	Version  string
	Device   string
}

Keybase holds basic information about the local Keybase executable

func New added in v2.0.3

func New(opts ...KeybaseOpt) *Keybase

New returns a new Keybase

func NewKeybase

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. This is deprecated and will be removed in a future update. Use New() instead.

func (*Keybase) AdvertiseCommands

func (k *Keybase) AdvertiseCommands(options AdvertiseCommandsOptions) error

AdvertiseCommands sends bot command advertisements. Valid values for the `Typ` field in chat1.AdvertiseCommandAPIParam are "public", "teamconvs", and "teammembers"

Example
var k = NewKeybase()

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

// Create BotAdvertisement
ads := AdvertiseCommandsOptions{
	Alias: "RSS Bot",
	Advertisements: []chat1.AdvertiseCommandAPIParam{
		{
			Typ: "public",
			Commands: []chat1.UserBotCommandInput{
				{
					Name:        "rss addfeed",
					Description: "Add RSS feed",
					Usage:       "<url>",
				},
				{
					Name:        "rss delfeed",
					Description: "Remove RSS feed",
					Usage:       "<url>",
				},
			},
		},
	},
}

// Send advertisement
k.AdvertiseCommands(ads)
Output:

func (*Keybase) ClearCommands

func (k *Keybase) ClearCommands() error

ClearCommands clears bot advertisements

func (*Keybase) CreateTeam

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

CreateTeam creates a new team

func (*Keybase) DeleteByChannel

func (k *Keybase) DeleteByChannel(channel chat1.ChatChannel, msgID chat1.MessageID) (chat1.SendRes, error)

DeleteByChannel reacts to a message in a channel

func (*Keybase) DeleteByConvID

func (k *Keybase) DeleteByConvID(convID chat1.ConvIDStr, msgID chat1.MessageID) (chat1.SendRes, error)

DeleteByConvID reacts to a message in a conversation id

func (*Keybase) Download

func (k *Keybase) Download(options DownloadOptions) error

Download downloads a file

func (*Keybase) DownloadFromChannel

func (k *Keybase) DownloadFromChannel(channel chat1.ChatChannel, msgID chat1.MessageID, output string) error

DownloadFromChannel downloads a file from a channel

func (*Keybase) DownloadFromConversation

func (k *Keybase) DownloadFromConversation(conv chat1.ConvIDStr, msgID chat1.MessageID, output string) error

DownloadFromConversation downloads a file from a conversation

func (*Keybase) EditByChannel

func (k *Keybase) EditByChannel(channel chat1.ChatChannel, msgID chat1.MessageID, message string, a ...interface{}) (chat1.SendRes, error)

EditByChannel sends an edit message to a channel

func (*Keybase) EditByConvID

func (k *Keybase) EditByConvID(convID chat1.ConvIDStr, msgID chat1.MessageID, message string, a ...interface{}) (chat1.SendRes, error)

EditByConvID sends an edit message to a conversation id

func (*Keybase) Exec

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

Exec executes the given Keybase command

func (*Keybase) GetConversations

func (k *Keybase) GetConversations(unreadOnly bool) ([]chat1.ConvSummary, error)

GetConversations returns a list of all conversations.

func (*Keybase) KVDelete

func (k *Keybase) KVDelete(team *string, namespace string, key string) (keybase1.KVDeleteEntryResult, error)

KVDelete deletes an entry

func (*Keybase) KVDeleteWithRevision

func (k *Keybase) KVDeleteWithRevision(team *string, namespace string, key string, revision int) (keybase1.KVDeleteEntryResult, error)

KVDeleteWithRevision deletes an entry, specifying the revision number

func (*Keybase) KVGet

func (k *Keybase) KVGet(team *string, namespace string, key string) (keybase1.KVGetResult, error)

KVGet returns an entry

func (*Keybase) KVListKeys

func (k *Keybase) KVListKeys(team *string, namespace string) (keybase1.KVListEntryResult, error)

KVListKeys returns all non-deleted keys for a namespace

func (*Keybase) KVListNamespaces

func (k *Keybase) KVListNamespaces(team *string) (keybase1.KVListNamespaceResult, error)

KVListNamespaces returns all namespaces for a team

func (*Keybase) KVPut

func (k *Keybase) KVPut(team *string, namespace string, key string, value string) (keybase1.KVPutResult, error)

KVPut puts an entry

func (*Keybase) KVPutWithRevision

func (k *Keybase) KVPutWithRevision(team *string, namespace string, key string, value string, revision int) (keybase1.KVPutResult, error)

KVPutWithRevision puts an entry, specifying the revision number

func (*Keybase) ListConvsOnName added in v2.0.4

func (k *Keybase) ListConvsOnName(channel chat1.ChatChannel) (*[]chat1.ConvSummary, error)

ListConvsOnName returns a list of all conversations for a chat1.ChatChannel

func (*Keybase) ListMembers

func (k *Keybase) ListMembers(options ListMembersOptions) (chat1.ChatMembersDetails, error)

ListMembers returns member information for a channel or conversation

func (*Keybase) ListMembersOfChannel

func (k *Keybase) ListMembersOfChannel(channel chat1.ChatChannel) (chat1.ChatMembersDetails, error)

ListMembersOfChannel returns member information for a channel

func (*Keybase) ListMembersOfConversation

func (k *Keybase) ListMembersOfConversation(convID chat1.ConvIDStr) (chat1.ChatMembersDetails, error)

ListMembersOfConversation returns member information for a conversation

func (*Keybase) ListUserMemberships

func (k *Keybase) ListUserMemberships(user string) (TeamAPI, error)

ListUserMemberships returns information about a given user's team memberships

func (*Keybase) NewChat

func (k *Keybase) NewChat(channel chat1.ChatChannel) Chat

NewChat returns a new Chat instance

func (*Keybase) NewTeam

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

NewTeam returns a new Team instance

func (*Keybase) NewWallet

func (k *Keybase) NewWallet() Wallet

NewWallet returns a new Wallet instance

func (*Keybase) ReactByChannel

func (k *Keybase) ReactByChannel(channel chat1.ChatChannel, msgID chat1.MessageID, message string, a ...interface{}) (chat1.SendRes, error)

ReactByChannel reacts to a message in a channel

func (*Keybase) ReactByConvID

func (k *Keybase) ReactByConvID(convID chat1.ConvIDStr, msgID chat1.MessageID, message string, a ...interface{}) (chat1.SendRes, error)

ReactByConvID reacts to a message in a conversation id

func (*Keybase) Read

func (k *Keybase) Read(options ReadMessageOptions) (chat1.Thread, error)

Read fetches chat messages

func (*Keybase) ReadChannel

func (k *Keybase) ReadChannel(channel chat1.ChatChannel) (chat1.Thread, error)

ReadChannel fetches chat messages for a channel

func (*Keybase) ReadChannelNext

func (k *Keybase) ReadChannelNext(channel chat1.ChatChannel, next []byte, num int) (chat1.Thread, error)

ReadChannelNext fetches the next page of messages for a chat channel.

func (*Keybase) ReadChannelPrevious

func (k *Keybase) ReadChannelPrevious(channel chat1.ChatChannel, previous []byte, num int) (chat1.Thread, error)

ReadChannelPrevious fetches the previous page of messages for a chat channel

func (*Keybase) ReadConversation

func (k *Keybase) ReadConversation(conv chat1.ConvIDStr) (chat1.Thread, error)

ReadConversation fetches chat messages for a conversation

func (*Keybase) ReadConversationNext

func (k *Keybase) ReadConversationNext(conv chat1.ConvIDStr, next []byte, num int) (chat1.Thread, error)

ReadConversationNext fetches the next page of messages for a conversation.

func (*Keybase) ReadConversationPrevious

func (k *Keybase) ReadConversationPrevious(conv chat1.ConvIDStr, previous []byte, num int) (chat1.Thread, error)

ReadConversationPrevious fetches the previous page of messages for a chat channel

func (*Keybase) ReplyByChannel

func (k *Keybase) ReplyByChannel(channel chat1.ChatChannel, replyTo chat1.MessageID, message string, a ...interface{}) (chat1.SendRes, error)

ReplyByChannel sends a reply message to a channel

func (*Keybase) ReplyByConvID

func (k *Keybase) ReplyByConvID(convID chat1.ConvIDStr, replyTo chat1.MessageID, message string, a ...interface{}) (chat1.SendRes, error)

ReplyByConvID sends a reply message to a conversation id

func (*Keybase) Run

func (k *Keybase) Run(handlers Handlers, options *RunOptions)

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

func (*Keybase) SendEphemeralByChannel

func (k *Keybase) SendEphemeralByChannel(channel chat1.ChatChannel, duration time.Duration, message string, a ...interface{}) (chat1.SendRes, error)

SendEphemeralByChannel sends an exploding chat message to a channel

func (*Keybase) SendEphemeralByConvID

func (k *Keybase) SendEphemeralByConvID(convID chat1.ConvIDStr, duration time.Duration, message string, a ...interface{}) (chat1.SendRes, error)

SendEphemeralByConvID sends an exploding chat message to a conversation id

func (*Keybase) SendMessage

func (k *Keybase) SendMessage(method string, options SendMessageOptions) (chat1.SendRes, error)

SendMessage sends a chat message

func (*Keybase) SendMessageByChannel

func (k *Keybase) SendMessageByChannel(channel chat1.ChatChannel, message string, a ...interface{}) (chat1.SendRes, error)

SendMessageByChannel sends a chat message to a channel

func (*Keybase) SendMessageByConvID

func (k *Keybase) SendMessageByConvID(convID chat1.ConvIDStr, message string, a ...interface{}) (chat1.SendRes, error)

SendMessageByConvID sends a chat message to a conversation id

func (*Keybase) UploadToChannel

func (k *Keybase) UploadToChannel(channel chat1.ChatChannel, title string, filename string) (chat1.SendRes, error)

UploadToChannel attaches a file to a channel The filename must be an absolute path

func (*Keybase) UploadToConversation

func (k *Keybase) UploadToConversation(conv chat1.ConvIDStr, title string, filename string) (chat1.SendRes, error)

UploadToConversation attaches a file to a conversation The filename must be an absolute path

func (*Keybase) UserCard

func (k *Keybase) UserCard(user string) (UserCardAPI, error)

UserCard pulls the information that is typically displayed when you open a user's profile.

func (*Keybase) UserLookup

func (k *Keybase) UserLookup(users ...string) (UserAPI, error)

UserLookup pulls information about users. The following fields are currently returned: basics, profile, proofs_summary, devices -- See https://keybase.io/docs/api/1.0/call/user/lookup for more info.

type KeybaseOpt added in v2.0.3

type KeybaseOpt interface {
	// contains filtered or unexported methods
}

KeybaseOpt configures a Keybase

func SetExePath added in v2.0.3

func SetExePath(path string) KeybaseOpt

SetExePath sets the path to the Keybase executable

func SetHomePath added in v2.0.3

func SetHomePath(path string) KeybaseOpt

SetHomePath sets the path to the Keybase home directory

type ListMembersOptions

type ListMembersOptions struct {
	Channel        chat1.ChatChannel
	ConversationID chat1.ConvIDStr `json:"conversation_id"`
}

ListMembersOptions holds a set of options to be passed to ListMembers

type ReadMessageOptions

type ReadMessageOptions struct {
	Channel        chat1.ChatChannel `json:"channel,omitempty"`
	ConversationID chat1.ConvIDStr   `json:"conversation_id,omitempty"`
	Pagination     *chat1.Pagination `json:"pagination,omitempty"`
	Peek           bool              `json:"peek"`
	UnreadOnly     bool              `json:"unread_only"`
	FailOffline    bool              `json:"fail_offline"`
}

ReadMessageOptions holds a set of options to be passed to Read

type RequestPayment

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

type RunOptions

type RunOptions struct {
	Capacity       int                 // Channel capacity for the buffered channel that holds messages. Defaults to 100 if not set
	Local          bool                // Subscribe to local messages
	HideExploding  bool                // Ignore exploding messages
	Dev            bool                // Subscribe to dev channel messages
	FilterChannel  chat1.ChatChannel   // Only subscribe to messages from specified channel
	FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels
}

RunOptions holds a set of options to be passed to Run

type SendMessageBody

type SendMessageBody struct {
	Body string
}

SendMessageBody holds the body string for all send and reply methods

type SendMessageOptions

type SendMessageOptions struct {
	Channel           chat1.ChatChannel  `json:"channel,omitempty"`
	ConversationID    chat1.ConvIDStr    `json:"conversation_id,omitempty"`
	Message           SendMessageBody    `json:",omitempty"`
	Filename          string             `json:"filename,omitempty"`
	Title             string             `json:"title,omitempty"`
	MessageID         chat1.MessageID    `json:"message_id,omitempty"`
	ConfirmLumenSend  bool               `json:"confirm_lumen_send"`
	ReplyTo           *chat1.MessageID   `json:"reply_to,omitempty"`
	ExplodingLifetime *ExplodingLifetime `json:"exploding_lifetime,omitempty"`
	UnreadOnly        bool               `json:"unread_only,omitempty"`
	NonBlock          bool               `json:"nonblock,omitempty"`
}

SendMessageOptions holds a set of options to be passed to SendMessage

type SendPayment

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

type Team

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

Team holds basic information about a team

func (Team) AddAdmins

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

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

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

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

AddUser adds a member to a team by username

func (Team) AddWriters

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

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

CreateSubteam creates a subteam

func (Team) MemberList

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

MemberList returns a list of a team's members

func (Team) RemoveUser

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

RemoveUser removes a member from a team

type TeamAPI

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 UserAPI

type UserAPI struct {
	Status uStatus `json:"status"`
	Them   []them  `json:"them"`
}

UserAPI holds information received from the user/lookup api

type UserCardAPI

type UserCardAPI struct {
	AirdropRegistered bool           `json:"airdrop_registered"`
	Blocked           bool           `json:"blocked"`
	FollowSummary     followSummary  `json:"follow_summary"`
	Profile           cardProfile    `json:"profile"`
	Status            uStatus        `json:"status"`
	TeamShowcase      []teamShowcase `json:"team_showcase"`
	TheyFollowYou     bool           `json:"they_follow_you"`
	UserBlocks        userBlocks     `json:"user_blocks"`
	YouFollowThem     bool           `json:"you_follow_them"`
}

UserCardAPI holds information received from the user/card api

type Wallet

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

Wallet holds basic information about a wallet

func (Wallet) CancelRequest

func (w Wallet) CancelRequest(requestID string) error

CancelRequest cancels a request for payment previously sent to a user

func (Wallet) RequestPayment

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

RequestPayment sends a request for payment to a user

func (Wallet) Send

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

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

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

StellarAddress returns the primary stellar address of a given user

func (Wallet) StellarUser

func (w Wallet) StellarUser(wallet string) (string, error)

StellarUser returns the keybase username of a given wallet address

func (Wallet) TxDetail

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

TxDetail returns details of a stellar transaction

type WalletAPI

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

Directories

Path Synopsis
types

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL