Browse Source

first pass on feedback command!

master
David Haukeness 5 years ago
parent
commit
4a1d0230d2
No known key found for this signature in database
GPG Key ID: 54F2372DDB7F9462
  1. 5
      README.md
  2. 11
      args.go
  3. 16
      commands.go
  4. 10
      handlers.go
  5. 12
      main.go
  6. 18
      utils.go

5
README.md

@ -21,7 +21,9 @@ This package requires the keybase binary installed on your system, and works on
#### Running: #### Running:
``` ```
-debug -debug
enables command debugging. enables command debugging to stdout
-feedback-convid string
sets the keybase chat1.ConvIDStr to send feedback to.
-log-convid string -log-convid string
sets the keybase chat1.ConvIDStr to log debugging to keybase chat. sets the keybase chat1.ConvIDStr to log debugging to keybase chat.
``` ```
@ -45,6 +47,7 @@ Required by keybase: (Must set all of these)
Required by this package: (Set the values you feel like, if you don't set them they won't be used) Required by this package: (Set the values you feel like, if you don't set them they won't be used)
- `BOT_DEBUG=true` - `BOT_DEBUG=true`
- `BOT_LOG_CONVID=<your keybase conversation id>` - `BOT_LOG_CONVID=<your keybase conversation id>`
- `BOT_FEEDBACK_CONVID=<your keybase conversation id>`
#### Example: #### Example:
`docker run --name myJitsi --rm -d -e KEYBASE_USERNAME=FOO -e KEYBASE_PAPERKEY="bar baz ..." -e KEYBASE_SERVICE=1 -e BOT_DEBUG=true haukeness/keybase-jitsi-bot` `docker run --name myJitsi --rm -d -e KEYBASE_USERNAME=FOO -e KEYBASE_PAPERKEY="bar baz ..." -e KEYBASE_SERVICE=1 -e BOT_DEBUG=true haukeness/keybase-jitsi-bot`

11
args.go

@ -18,6 +18,8 @@ func (b *bot) parseArgs(args []string) error {
cliConfig := botConfig{} cliConfig := botConfig{}
flags.BoolVar(&cliConfig.Debug, "debug", false, "enables command debugging to stdout") flags.BoolVar(&cliConfig.Debug, "debug", false, "enables command debugging to stdout")
flags.StringVar(&cliConfig.LogConvIDStr, "log-convid", "", "sets the keybase chat1.ConvIDStr to log debugging to keybase chat.") flags.StringVar(&cliConfig.LogConvIDStr, "log-convid", "", "sets the keybase chat1.ConvIDStr to log debugging to keybase chat.")
flags.StringVar(&cliConfig.FeedbackConvIDStr, "feedback-convid", "", "sets the keybase chat1.ConvIDStr to send feedback to.")
flags.StringVar(&cliConfig.FeedbackTeamAdvert, "feedback-team-advert", "", "sets the keybase team/channel to advertise feedback. @team#channel")
if err := flags.Parse(args[1:]); err != nil { if err := flags.Parse(args[1:]); err != nil {
return err return err
} }
@ -30,6 +32,12 @@ func (b *bot) parseArgs(args []string) error {
if cliConfig.LogConvIDStr != "" { if cliConfig.LogConvIDStr != "" {
b.config.LogConvIDStr = cliConfig.LogConvIDStr b.config.LogConvIDStr = cliConfig.LogConvIDStr
} }
if cliConfig.FeedbackConvIDStr != "" {
b.config.FeedbackConvIDStr = cliConfig.FeedbackConvIDStr
}
if cliConfig.FeedbackTeamAdvert != "" {
b.config.FeedbackTeamAdvert = cliConfig.FeedbackTeamAdvert
}
} }
// then print the running options // then print the running options
@ -37,6 +45,9 @@ func (b *bot) parseArgs(args []string) error {
if b.config.LogConvIDStr != "" { if b.config.LogConvIDStr != "" {
b.debug("Logging to conversation %s", b.config.LogConvIDStr) b.debug("Logging to conversation %s", b.config.LogConvIDStr)
} }
if b.config.FeedbackConvIDStr != "" {
b.debug("Feedback enabled to %s and advertising %s", b.config.FeedbackConvIDStr, b.config.FeedbackTeamAdvert)
}
return nil return nil
} }

16
commands.go

@ -19,3 +19,19 @@ func (b *bot) setupMeeting(convid chat1.ConvIDStr, sender string, words []string
message := fmt.Sprintf("@%s here's your meeting: %s", sender, meeting.getURL()) message := fmt.Sprintf("@%s here's your meeting: %s", sender, meeting.getURL())
b.k.SendMessageByConvID(convid, message) b.k.SendMessageByConvID(convid, message)
} }
func (b *bot) sendFeedback(convid chat1.ConvIDStr, mesgID chat1.MessageID, sender string, message string) {
b.debug("feedback recieved in %s", convid)
if b.config.FeedbackConvIDStr != "" {
fcID := chat1.ConvIDStr(b.config.FeedbackConvIDStr)
if _, err := b.k.SendMessageByConvID(fcID, "Feedback from @%s:\n```%s```", sender, message); err != nil {
b.k.ReplyByConvID(convid, mesgID, "I'm sorry, I was unable to send your feedback because my benevolent overlords have not set a destination for feedback. :sad:")
log.Printf("Unable to send feedback: %s", err)
} else {
b.k.ReplyByConvID(convid, mesgID, "Thanks! Your feedback has been sent to my human overlords!")
b.debug("feedback sent")
}
} else {
b.debug("feedback not enabled. set --feedback-convid or BOT_FEEDBACK_CONVID")
}
}

10
handlers.go

@ -54,6 +54,8 @@ func (b *bot) chatHandler(m chat1.MsgSummary) {
switch words[1] { switch words[1] {
case "meet": case "meet":
b.setupMeeting(m.ConvID, m.Sender.Username, words, m.Channel.MembersType) b.setupMeeting(m.ConvID, m.Sender.Username, words, m.Channel.MembersType)
case "feedback":
b.sendFeedback(m.ConvID, m.Id, m.Sender.Username, m.Content.Text.Body)
} }
} }
} }
@ -63,10 +65,16 @@ func (b *bot) chatHandler(m chat1.MsgSummary) {
words := strings.Fields(m.Content.Text.Body) words := strings.Fields(m.Content.Text.Body)
// strip the ! from the first word, and lowercase to derive the command // strip the ! from the first word, and lowercase to derive the command
thisCommand := strings.ToLower(strings.Replace(words[0], "!", "", 1)) thisCommand := strings.ToLower(strings.Replace(words[0], "!", "", 1))
maybeSubCommand := strings.ToLower(words[1])
// decide if this is askind for extended commands // decide if this is askind for extended commands
switch thisCommand { switch thisCommand {
case "jitsi": case "jitsi":
b.setupMeeting(m.ConvID, m.Sender.Username, words, m.Channel.MembersType) switch maybeSubCommand {
case "feedback":
b.sendFeedback(m.ConvID, m.Id, m.Sender.Username, m.Content.Text.Body)
default:
b.setupMeeting(m.ConvID, m.Sender.Username, words, m.Channel.MembersType)
}
default: default:
return return
} }

12
main.go

@ -24,8 +24,10 @@ type bot struct {
// botConfig hold env and cli flags and options // botConfig hold env and cli flags and options
// fields must be exported for package env (reflect) to work // fields must be exported for package env (reflect) to work
type botConfig struct { type botConfig struct {
Debug bool `env:"BOT_DEBUG" envDefault:"false"` Debug bool `env:"BOT_DEBUG" envDefault:"false"`
LogConvIDStr string `env:"BOT_LOG_CONVID" envDefault:""` LogConvIDStr string `env:"BOT_LOG_CONVID" envDefault:""`
FeedbackConvIDStr string `env:"BOT_FEEDBACK_CONVID" envDefault:""`
FeedbackTeamAdvert string `env:"BOT_FEEDBACK_TEAM_ADVERT" envDefault:""`
} }
// hold reply information when needed // hold reply information when needed
@ -81,6 +83,12 @@ func (b *bot) registerCommands() {
Description: "Starts a meet.jit.si meeting", Description: "Starts a meet.jit.si meeting",
Usage: "", Usage: "",
}, },
{
Name: "jitsi feedback",
Description: "Tell us how we're doing!",
Usage: "",
ExtendedDescription: getFeedbackExtendedDescription(b.config),
},
}, },
}, },
}, },

18
utils.go

@ -2,6 +2,9 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"samhofi.us/x/keybase/types/chat1"
) )
// this JSON pretty prints errors and debug // this JSON pretty prints errors and debug
@ -9,3 +12,18 @@ func p(b interface{}) string {
s, _ := json.MarshalIndent(b, "", " ") s, _ := json.MarshalIndent(b, "", " ")
return string(s) return string(s)
} }
func getFeedbackExtendedDescription(bc botConfig) *chat1.UserBotExtendedDescription {
if bc.FeedbackTeamAdvert != "" {
return &chat1.UserBotExtendedDescription{
Title: "!jitsi feedback",
DesktopBody: fmt.Sprintf("Please note: Your feedback will be public!\nYour feedback will be posted to %s", bc.FeedbackTeamAdvert),
MobileBody: fmt.Sprintf("Please note: Your feedback will be public!\nYour feedback will be posted to %s", bc.FeedbackTeamAdvert),
}
}
return &chat1.UserBotExtendedDescription{
Title: fmt.Sprintf("!jitsi feedback"),
DesktopBody: "Please note: Your feedback will be public!",
MobileBody: "Please note: Your feedback will be public!",
}
}

Loading…
Cancel
Save