GithubHelp home page GithubHelp logo

target / flottbot Goto Github PK

View Code? Open in Web Editor NEW
324.0 324.0 57.0 954 KB

A chatbot framework written in Go. All configurations are made in YAML files, or inside scripts written in your favorite language.

Home Page: https://target.github.io/flottbot-docs/

License: Apache License 2.0

Ruby 0.52% JavaScript 0.02% Python 0.04% Shell 0.06% Go 96.45% Dockerfile 0.46% Makefile 1.94% Mustache 0.51%
bot chatbot chatbot-framework chatops discord go golang google-chat hacktoberfest slack telegram yaml

flottbot's People

Contributors

alankan886 avatar barneysowood avatar cameronjhall avatar delta592 avatar dependabot[bot] avatar dpritchett avatar empyreus avatar jordansussman avatar justmiles avatar ormazz avatar pronovic avatar renjithpk avatar renovate[bot] avatar sarge avatar sjqnn avatar sspaink avatar stahnma avatar vsychov avatar wass3r avatar wass3rw3rk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flottbot's Issues

Turn @ user mention into link

Detect when @user.name is in format_output and attempt to look up user ID to format as clickable link.

Might need to consider scenario where the user wants to output @... without doing a lookup.

Users without access aren't messaged reason

Report

What did you do?

Created a rule with access restrictions

What did you expect to happen?

User without access should have gotten a message that they don't have access

What happened instead?

Nothing

Screenshots

n/a

Your Environment

Please complete the following information):

  • Flottbot version: 0.1.2
  • OS: macOS
  • OS version: 10.13.6
  • Bot YAML (see below)
  • Rule YAML (see below) if applicable
# please paste .bot.yml here (remove any sensitive information!)
# please paste contents of your rule, if applicable (remove any sensitive information!)

Additional context

Add any other context about the problem here.

Native way to throttle bot usage

Limit how many times a bot will trigger a rule based on a user defined param. For example:

I'm running a bot on a remote system/ against an api that doesn't have rate limiting in place, i could have my remote system/api ddos'ed by a malicious user through the bot. Maybe set some reasonable default of 60 times/hr or something.

Listed rule args should be optional

Currently, the listed respond arguments in rules have a mandatory usage policy.

We want to be able to make args be optional for usage.

Example:

respond: metrics
args:
  - startDate
  - endDate

@flottbot metrics will not work

@flottbot metrics start_date end_date will work

I think we'd also want the bot owner to determine whether they are optional. Maybe something like:

repond: metrics
args:
  - startDate?
  - endDate?

Add ability to use capturing group from regex in actions

Currently, regex is fairly simple.. you can just look for patterns and take action on it. it would be nice to be able to use capturing groups and assign to variables to use throughout actions, etc.

simple example:

respond: /unlock\s[\<'"]?(.*)[\>'"]?/
args:
  - user

If someone typed unlock <name>, name would be assigned to user or ${user}

Rename args prop to expose_args

name: test
match: command
args:
  - var1

to

name: test
match: command
expose_args:
  - var1

This is consistent with expose_json_fields. So, any time we expose variable from within rules we would use the expose_ prefix.

Provide an Anti-spamming mechanism.

For hear rules, allow bot creators to limit a bot from responding multiple times in the same thread. In the case that a bot doesn't accurately answer a user's question with it's first response, provide a mechanism to prevent the bot from chiming in additional times in a thread. I don't know how we'd want to implement this exactly, but I think it would be a nice configurable thing we could include.

Scheduler spec that utilize "/" will not work

Cron specs that utilize / will not work.

  • e.g. */1 * * * * (at every minute) fails, but 0 * * * * (at minute 0) works

This is because the golang package we use to create cron jobs robfig, does not support said cron spec syntax.

Misleading error message on startup

Report

What did you do?

Ran the bot normally. Slack token environment variable set.

What did you expect to happen?

Not see the following in the console log:

ERRO[0000] Slack Interactive Components callback path is empty:

What happened instead?

I saw the following in the console log:

ERRO[0000] Slack Interactive Components callback path is empty:

Your Environment

  • Run flottbot --version and paste the output here: Version : 0.1.0
  • What OS are you running on? macOS Sierra version 10.12.6
  • Your bot.yml (remove any sensitive information!)
  • Maybe the contents of the .yml for the rule you're trying to run, if applicable (remove any sensitive information!)
  # metadata (for logging)
name: thorhousebot # EDIT this (name of bot)

# chat applications
chat_application: slack # EDIT (network to use, e.g. 'slack')
slack_token: ${SLACK_TOKEN} # EDIT ${SLACK_TOKEN}

# system
cli: false # leave this to be 'true' as default
# true: enables ability to turn on CLI mode.
# false: disables ability to turn on CLI mode.

scheduler: false
# true: enables rule scheduling
# false: disables rule scheduling

debug: true
# true: enable logging to console
# false: disable logging

log_json: false
# true: logs will be in JOSN format
# false: logs will be in plain text

# for advanced messaging capabilities
webhook: false # leave this to be 'false' as default

# for prometheus metrics capabilities
metrics: false # 'false': disable prometheus metrics
# please paste contents of your rule, if applicable (remove any sensitive information!)

Add HTTP retry mechanism

Use case:

If an error is returned by the client (connection errors, etc.), or if a 500-range response code is received, then a retry is invoked after a wait period.

Thoughts:

Looks like the standard golang HTTP library doesn't have a native way to support this. It may be worthwhile to explore other libraries like heimdall or go-retryablehttp that support this.

HTTP Post should support raw data

Currently, the query_data options in a POST builds the request as JSON. Not all endpoints are built to support this. In some cases, it wants just raw data.

I propose adding a raw option to the query_data that will take the data and just add it to the post.

Allowing triggering CLI mode with flag instead of config file

Instead of having to mod the bot.yml, you should be able to pass a flag to the flottbot binary. The usage would look something like:

flottbot --cli or something similar, which would ignore any keys/tokens in the bot.yml.

This would make local dev for bot makers easier.

Exposed ports don't appear to be documented

Report

3 ports are exposed by the flottbot dockerfile:
EXPOSE 8080 3000 4000

None of them are explicitly mentioned in the documentation (e.g. port 8080 is used for X). #56 mentions that these are for prometheus, slack events, and slack interactions api receiver, but doesn't mention which port is intended for which purpose.

What did you do?

Read docs, read the Dockerfile, read the example.

The config-example/bot.yml says:

# true: enables prometheus metrics on localhost port 8080

prommetric.go says:

go http.ListenAndServe(":8080", promRouter)

which indicates that it listens on INADDR_ANY.

helper.go listens on :3000 and remote.go listens on :4000. Is there any reason these aren't config options, and/or aren't documented?

What did you expect to happen?

Ports named and documented in configurations, with the defaults as defaults.

What happened instead?

No documentation.

Your Environment

Please complete the following information):

  • Flottbot version: github HEAD
  • OS: N/A
  • OS version: N/A
  • Bot YAML: N/A
  • Rule YAML: N/A

I'm happy to work up a PR if what I'm asking about seems reasonable.

Helper functions for templating

Shortcuts for common more verbose go templates.

ability: |-
        {{ range .abilities }}
          - {{ .ability.name -}}
        {{ end }}

vs

ability: .abilities[*].ability.name

Don't panic on unsupported regex error

Certain regex when used in respond/hear will cause a panic, ie. negative look ahead which is not supported by Golang.

Example query: /^(?!.*(hello|goodday|hi)).*issue.*$/

Also, provide debug information for bot admins when common regex patterns are passed in that will not give expected results, such as /.*/gi

Exec action does not properly handle missing binary

Report

What did you do?

Created a rule with an exec action that had a cmd that didn't exist on the system.

What did you expect to happen?

Expected error handling to occur

What happened instead?

The bot outputted fork/exec ./foo/bar: no such file or directory directly to Discord.

Your Environment

Please complete the following information):

  • Flottbot version: master branch
  • OS: macOS
# please paste .bot.yml here (remove any sensitive information!)
# chat applications
chat_application: discord

# Discord chat application specific fields.
# required
discord_token: ${DISCORD_TOKEN}

# system
cli: false
# true: enables ability to turn on CLI mode.
# false: disables ability to turn on CLI mode.

scheduler: false
# true: enables rule scheduling
# false: disables rule scheduling

debug: true
# true: enable logging to console
# false: disable logging

log_json: false
# true: logs will be in JSON format
# false: logs will be in plain text

metrics: false
# meta
name: script-rule
active: true
# trigger and args
respond: script
reaction: "๐Ÿ‘€"
# actions
actions:
  - name: sample script
    type: exec
    cmd: ./foo/bar
    update_reaction: |-
      {{ if (eq `${_exec_status}` "0") }}
        โœ…
      {{ else }}
        โ—
      {{ end }}
# response
format_output: "${_exec_output}"
direct_message_only: false
# help
help_text: script
include_in_help: true

Additional context

Some initial bugging seems to tell me that the error handling struct of the script isn't handling this scenario, so we are falling into the default

default:
. Looks like the case statement needs to have *os.PathError added to it.

Handle ugly panic stack trace

Report

What did you do?

  1. Set the metrics field to false
  2. Build the docker image. Here's my Dockerfile:
FROM target/flottbot:golang

ADD config config

CMD ["/go/flottbot"]
  1. Run the docker image without any environment variables (this will cause the stack trace):
docker run -it thorhousebot

What did you expect to happen?

I was expecting a prettier and more informative error message, i.e. "Your slack token was not found" or something like that.

What happened instead?

Ugly stack trace poop.

INFO[0000] Configuring bot...
WARN[0000] Could not set Slack Token: Variable 'SLACK_TOKEN' has not been defined.
ERRO[0000] Slack Interactive Components callback path is empty:
INFO[0000] Configured bot 'thorhousebot'!
DEBU[0000] Looking for rules directory...
DEBU[0000] Fetching all rule YAML files...
DEBU[0000] Reading and parsing rule YAML files...
INFO[0000] Configured 'thorhousebot' rules!
fatal error: all goroutines are asleep - deadlock!

goroutine 1 [semacquire]:
sync.runtime_Semacquire(0xc000025998)
        /usr/local/go/src/runtime/sema.go:56 +0x39
sync.(*WaitGroup).Wait(0xc000025990)
        /usr/local/go/src/sync/waitgroup.go:130 +0x64
main.main()
        /go/src/github.com/target/flottbot/main.go:71 +0x27c

goroutine 8 [chan receive]:
github.com/target/flottbot/core.Matcher(0xc00001ef00, 0xc00001ef60, 0xc00013a420, 0xc00001eea0, 0xc000087900)
        /go/src/github.com/target/flottbot/core/matcher.go:23 +0x7a
created by main.main
        /go/src/github.com/target/flottbot/main.go:61 +0x212

goroutine 9 [chan receive]:
github.com/target/flottbot/core.Outputs(0xc00001ef60, 0xc00001eea0, 0xc000087900)
        /go/src/github.com/target/flottbot/core/outputs.go:19 +0x9c
created by main.main
        /go/src/github.com/target/flottbot/main.go:62 +0x248

Your Environment

  • Run flottbot --version and paste the output here: Version : 0.1.0
  • What OS are you running on? macOS Sierra version 10.12.6
  • Your bot.yml (remove any sensitive information!)
  • Maybe the contents of the .yml for the rule you're trying to run, if applicable (remove any sensitive information!)
name: thorhousebot 

chat_application: slack 
slack_token: ${SLACK_TOKEN} 

cli: false 

scheduler: false

debug: true

log_json: false

webhook: false

metrics: false 
# please paste contents of your rule, if applicable (remove any sensitive information!)

Ability to respond to emoji added to message

I'd love to have the ability to respond to the event of when an emoji is added to a message.

Use case:
Our bot monitors our support rooms. We have users who post into our support who sometimes don't provide enough context or information for us to support them. Instead of us manually responding: "Please provide more information" it'd be nice to append the :question: emoji on the message (or something similar) and have our bot create a thread with the message and useful links

Dependent on #23

Ability to trigger off of events

Look into providing an ability to trigger a rule off of chat network events, like channel joined, DM opened, emoji reaction (?), etc.

Provide Hours a bot will be responsive.

Provide a mechanism that will turn on a chatbot rule on for only a specified period of time. I could see this being implemented in the rule.yml like so:

# metadata
name: hello
active: true
active_start: 16:00
active_stop: 09:00

This would turn the rule active between 4pm-9am for example.

Random response when multiple rules have same trigger

Report

What did you do?

Added multiple rules with different file names, but had the same respond keyword.

What did you expect to happen?

Warn that you have multiple rules with the same respond.

What happened instead?

Rules are randomly triggered without notification to the bot.

Dynamically populate help if no help text defined

In most cases it's just the match text plus arguments which are available in YAML. We can automatically compose a help message based on that. But we should keep the ability to override for cases where you don't want to show the 'match' value, eg. in cases where it's some crazy regex

For example:

respond: hello
args:
  - firstname
  - lastname

Based on that we know we can show hello <firstname> <lastname>

Use limit_to_channels instead of limit_to_rooms

Our two supported remotes use the terminology channel so we should probably use that instead of room.

This was likely a hipchat leftover, though we'll have to make it backwards compatible and deprecate the old way

Send enter command/character to CLI mode

When you run a bot in CLI mode and issue a command, it responds but it doesn't display the next command prompt, i.e.

flottbot>

It still continues to work even without the flottbot> prompt, but it can still throw off users.

Create bot cooldown periods

Ideally we could implement some sort of cooldown or mute functionality at the bot level. This would be useful for scenarios where you don't want excessive spam.

This functionality could be created at all of the following levels:

  • global (entire slack/discord server)
  • channel
  • user

Clean up remotes

Ensure remotes are set up and used properly; ie. avoid direct references to remote APIs outside of /remote

Allow for empty format_output field

Right now, if format_output is left empty or not instantiated in a rule, it relays a message to the user that the field is empty. I think this should be a log not a message to the user. There are use cases where you do not care to have output to the user triggering the rule.

Handle Emoji Response on HTTP Timeouts

We can react with emojis based with HTTP responses that have gone through. But if there is a timeout, we don't have a way to handle that.

We can/should return a 408.

Refactor to use single port

Currently we expose three ports, for:

  1. Prometheus (8080)
  2. Slack Events API Receiver (3000)
  3. Slack Interactions API Receiver (4000)

Consider refactoring to use a single port. Provide an ability to register a handler for any path and by default register handlers for the above, if applicable.

Also, add a configuration option to set the port the user wants to use.

This will reduce number of ports to expose/manage and allow easier deployments in some cases.

Refactor access_check

isMemberOfGroup in /utils/access_check.go needs to get refactored/moved. /remote should deal with context routing.

Configure travis ci

We need to setup travis ci to test, build, and publish binaries.

#3 is working on fine tuning the configuration.

go build . does not produces the ./flottbot binary

Report

What did you do?

  1. step by step the CONTRIBUTING documentation to get started.
  2. run the command go build . to build the project

What did you expect to happen?

Compile the code and obtain the ./flottbot binary

What happened instead?

can't load package: package github.com/target: no Go files in /go/src/github.com/target

Screenshots

image

Your Environment

Please complete the following information):

  • Flottbot version: โ„น๏ธ i cannot compile it yet
  • OS: Debian 9
  • OS version: Kernel 4.9.0-8-amd64

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.