Giter Club home page Giter Club logo

go-keybase-chat-bot's Introduction

go-keybase-chat-bot

Script Keybase Chat in Go!

This module is a side-project/work in progress and may change or have crashers, but feel free to play with it. As long as you're logged in as a Keybase user, you can use this module to script basic chat commands.

Installation

Make sure to install Keybase.

go get -u github.com/keybase/go-keybase-chat-bot/...

Hello world

package main

import (
	"flag"
	"fmt"
	"os"

	"github.com/keybase/go-keybase-chat-bot/kbchat"
)

func fail(msg string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, msg+"\n", args...)
	os.Exit(3)
}

func main() {
	var kbLoc string
	var kbc *kbchat.API
	var err error

	flag.StringVar(&kbLoc, "keybase", "keybase", "the location of the Keybase app")
	flag.Parse()

	if kbc, err = kbchat.Start(kbLoc); err != nil {
		fail("Error creating API: %s", err.Error())
	}

	tlfName := fmt.Sprintf("%s,%s", kbc.Username(), "kb_monbot")
	fmt.Printf("saying hello on conversation: %s\n", tlfName)
	if err = kbc.SendMessageByTlfName(tlfName, "hello!"); err != nil {
		fail("Error sending message; %s", err.Error())
	}
}

Commands

Start(keybaseLocation string) *API

This must be run first in order to start the Keybase JSON API stdin/stdout interactive mode.

API.SendMessageByTlfName(tlfName string, body string) error

send a new message by specifying a TLF name

API.SendMessage(convID string, body string) error

send a new message by specifying a conversation ID

API.GetConversations(unreadOnly bool) ([]Conversation, error)

get all conversations, optionally filtering for unread status

API.GetTextMessages(convID string, unreadOnly bool) ([]Message, error)

get all text messages, optionally filtering for unread status

Reads the messages in a channel. You can read with or without marking as read.

API.ListenForNextTextMessages() NewMessageSubscription

Returns an object that allows for a bot to enter into a loop calling NewMessageSubscription.Read to receive any new message across all conversations (except the bots own messages). See the following example:

	sub := kbc.ListenForNewTextMessages()
	for {
		msg, err := sub.Read()
		if err != nil {
			fail("failed to read message: %s", err.Error())
		}

		if err = kbc.SendMessage(msg.Conversation.Id, msg.Message.Content.Text.Body); err != nil {
			fail("error echo'ing message: %s", err.Error())
		}
	}

TODO:

  • attachment handling (posting/getting)
  • edit/delete
  • many other things!

Contributions

  • welcomed!

go-keybase-chat-bot's People

Contributors

mmaxim avatar maxtaco avatar

Watchers

James Cloos avatar Matt Borowiec avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.