groupbot

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2018 License: MIT Imports: 19 Imported by: 0

README

GroupBot

Build Status Go Report Card Docs License

Overview

GroupBot is a bot that allows you to share information about yourself with the team. It was initially created to share information for ordering tshirts. It currently stores data in a Google Sheet.

Configuration

Set the following environment variables:

Variable Type Required Notes
GROUPBOT_ENGINE string y aws or nethttp
GROUPBOT_PORT integer n local port number for net/http
GROUPBOT_REQUEST_FUZZY_AT_MENTION_MATCH boolean n Match non-completed at mentions.
GROUPBOT_RESPONSE_AUTO_AT_MENTION boolean n
GOOGLE_SERVICE_ACCOUNT_JWT JSON string y
GOOGLE_SPREADSHEET_ID string y ID as in URL
GOOGLE_SHEET_INDEX integer y sheet index, e.g. 0
RINGCENTRAL_BOT_ID string y bot personId in Glip
RINGCENTRAL_BOT_NAME string y bot name in Glip for fuzzy at matching
RINGCENTRAL_SERVER_URL string y Base API URL, e.g. https://platform.ringcentral.com
RINGCENTRAL_TOKEN_JSON JSON string y JSON token as returned by /oauth/token endpoint

Using the AWS Engine

To use the AWS Lambda engine, you need an AWS account. If you don't hae one, the free trial account includes 1 million free Lambda requests per month forever and 1 million free API Gateway requests per month for the first year.

Installation via AWS Lambda

See the AWS docs for deployment:

https://docs.aws.amazon.com/lambda/latest/dg/lambda-go-how-to-create-deployment-package.html

Using the aws-cli you can use the following approach:

$ GOOS=linux go build main.go
$ zip main.zip ./main
# --handler is the path to the executable inside the .zip
$ aws lambda create-function --region us-east-1 --function-name Databot --memory 128 --role arn:aws:iam::account-id:role/execution_role --runtime go1.x --zip-file fileb://main.zip --handler main

Documentation

Index

Constants

View Source
const (
	CharQuoteLeft  = "“"
	CharQuoteRight = "”"
)
View Source
const ValidationTokenHeader = "Validation-Token"

Variables

This section is empty.

Functions

func GetGoogleApiClient added in v0.1.1

func GetGoogleApiClient(appConfig AppConfig) (*http.Client, error)

func GetRingCentralApiClient added in v0.1.1

func GetRingCentralApiClient(appConfig AppConfig) (*rc.APIClient, error)

func GetSheetsMap added in v0.1.1

func GetSheetsMap(googClient *http.Client, appConfig AppConfig) (sheetsmap.SheetsMap, error)

func ServeAwsLambda added in v0.1.1

func ServeAwsLambda(intentRouter IntentRouter)

func ServeNetHttp added in v0.1.1

func ServeNetHttp(intentRouter IntentRouter)

Types

type AppConfig added in v0.1.1

type AppConfig struct {
	Port                               int64  `env:"GROUPBOT_PORT"`
	GroupbotRequestFuzzyAtMentionMatch bool   `env:"GROUPBOT_REQUEST_FUZZY_AT_MENTION_MATCH"`
	GroupbotResponseAutoAtMention      bool   `env:"GROUPBOT_RESPONSE_AUTO_AT_MENTION"`
	GroupbotPostSuffix                 string `env:"GROUPBOT_POST_SUFFIX"`
	GroupbotCharQuoteLeft              string `env:"GROUPBOT_CHAR_QUOTE_LEFT"`
	GroupbotCharQuoteRight             string `env:"GROUPBOT_CHAR_QUOTE_RIGHT"`
	RingCentralTokenJSON               string `env:"RINGCENTRAL_TOKEN_JSON"`
	RingCentralServerURL               string `env:"RINGCENTRAL_SERVER_URL"`
	RingCentralWebhookURL              string `env:"RINGCENTRAL_WEBHOOK_URL"`
	RingCentralBotId                   string `env:"RINGCENTRAL_BOT_ID"`
	RingCentralBotName                 string `env:"RINGCENTRAL_BOT_NAME"`
	GoogleSvcAccountJWT                string `env:"GOOGLE_SERVICE_ACCOUNT_JWT"`
	GoogleSpreadsheetId                string `env:"GOOGLE_SPREADSHEET_ID"`
	GoogleSheetIndex                   int64  `env:"GOOGLE_SHEET_INDEX"`
}

func (*AppConfig) AppendPostSuffix added in v0.1.1

func (ac *AppConfig) AppendPostSuffix(s string) string

func (*AppConfig) Quote added in v0.1.1

func (ac *AppConfig) Quote(s string) string

type EventResponse

type EventResponse struct {
	StatusCode int               `json:"statusCode,omitempty"`
	Headers    map[string]string `json:"headers,omitempty"`
	Message    string            `json:"message,omitempty"`
}

func (*EventResponse) ToJson

func (er *EventResponse) ToJson() []byte

type GlipPostEventInfo added in v0.1.1

type GlipPostEventInfo struct {
	PostEvent        *rc.GlipPostEvent
	GroupMemberCount int64
	CreatorInfo      *rc.GlipPersonInfo
	TryCommandsLc    []string
}

type Groupbot added in v0.1.1

type Groupbot struct {
	AppConfig         AppConfig
	RingCentralClient *rc.APIClient
	GoogleClient      *http.Client
	SheetsMap         sheetsmap.SheetsMap
	IntentRouter      IntentRouter
}

func (*Groupbot) HandleAwsLambda added in v0.1.1

func (*Groupbot) HandleNetHTTP added in v0.1.1

func (bot *Groupbot) HandleNetHTTP(res http.ResponseWriter, req *http.Request)

func (*Groupbot) Initialize added in v0.1.1

func (bot *Groupbot) Initialize() (EventResponse, error)

func (*Groupbot) ProcessEvent added in v0.1.1

func (bot *Groupbot) ProcessEvent(reqBodyBytes []byte) (*EventResponse, error)

func (*Groupbot) SendGlipPost added in v0.1.1

func (bot *Groupbot) SendGlipPost(glipPostEventInfo *GlipPostEventInfo, reqBody rc.GlipCreatePost) (*EventResponse, error)

type Intent added in v0.1.1

type Intent struct {
	Type         IntentType
	Strings      []string
	Regexps      []*regexp.Regexp
	HandleIntent func(bot *Groupbot, glipPostEventInfo *GlipPostEventInfo) (*EventResponse, error)
}

type IntentRouter added in v0.1.1

type IntentRouter struct {
	Intents []Intent
}

func NewIntentRouter added in v0.1.1

func NewIntentRouter() IntentRouter

func (*IntentRouter) ProcessRequest added in v0.1.1

func (ir *IntentRouter) ProcessRequest(bot *Groupbot, glipPostEventInfo *GlipPostEventInfo) (*EventResponse, error)

func (*IntentRouter) ProcessRequestSingle added in v0.1.1

func (ir *IntentRouter) ProcessRequestSingle(bot *Groupbot, textNoBotMention string, glipPostEventInfo *GlipPostEventInfo) (*EventResponse, error)

type IntentType added in v0.1.1

type IntentType int
const (
	MatchString IntentType = iota
	MatchStringLowerCase
	MatchRegexp
	MatchAny
)

Directories

Path Synopsis
examples
server command
handlers
me
set

Jump to

Keyboard shortcuts

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