groupbot

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 23 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
GROUPBOT_POST_SUFFIX string n
GOOGLE_SERVICE_ACCOUNT_JWT JSON string y
GOOGLE_SPREADSHEET_ID string y ID as in URL
GOOGLE_SHEET_TITLE_RECORDS string y sheet title for data records, e.g. Records
GOOGLE_SHEET_TITLE_METADATA string y sheet title for metadata, e.g. Metadata
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:

$ cd ./apps/server
$ 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
Keepalive

In production, there are are reasons why a RingCentral webhook may fail and become blacklisted. These should be tracked down an eliminated. If there are reasons to reenable the webhook, you can deploy the [rchooks] RingCentral Lambda keepalive function:

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.2.2

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

func GetRingCentralAPIClient added in v0.2.2

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

func GetSheetsMap added in v0.1.1

func GetSheetsMap(googClient *http.Client, spreadsheetID string, sheetTitle string) (sheetsmap.SheetsMap, error)

func ServeAwsLambda added in v0.1.1

func ServeAwsLambda(intentRouter IntentRouter)

func ServeNetHTTP added in v0.2.2

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"`
	GoogleSheetTitleRecords            string `env:"GOOGLE_SHEET_TITLE_RECORDS"`
	GoogleSheetTitleMetadata           string `env:"GOOGLE_SHEET_TITLE_METADATA"`
}

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 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
	SheetsMapMeta     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() (hum.ResponseInfo, error)

func (*Groupbot) ProcessEvent added in v0.1.1

func (bot *Groupbot) ProcessEvent(reqBodyBytes []byte) (*hum.ResponseInfo, error)

func (*Groupbot) SendGlipPost added in v0.1.1

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

type Intent added in v0.1.1

type Intent struct {
	Type         IntentType
	Strings      []string
	Regexps      []*regexp.Regexp
	HandleIntent func(bot *Groupbot, glipPostEventInfo *GlipPostEventInfo) (*hum.ResponseInfo, 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) (*hum.ResponseInfo, error)

func (*IntentRouter) ProcessRequestSingle added in v0.1.1

func (ir *IntentRouter) ProcessRequestSingle(bot *Groupbot, textNoBotMention string, glipPostEventInfo *GlipPostEventInfo) (*hum.ResponseInfo, error)

type IntentType added in v0.1.1

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

Directories

Path Synopsis
apps
handlers
me
set

Jump to

Keyboard shortcuts

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