• Stars
    star
    178
  • Rank 210,020 (Top 5 %)
  • Language
    CoffeeScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A shot of love for your favorite chat client.

Heartbot

Heartbot is a Hubot integration that can be plugged into Slack, Hipchat, IRC, or other chat clients. Once installed, type things like "ugh", ":(", or "kitty me" and Heartbot will bring a little love and joy into the room. Spread the love on Twitter with #heartbot

Getting Started

First, you need to have NodeJS installed on your server:

Then, you will want to install Hubot. Start by installing the yo and generator-hubot packages globally:

sudo npm install -g yo generator-hubot

Generate a Hubot instance:

mkdir heartbot
cd heartbot
yo hubot

You will be prompted for to choose a chat adapter. A list of chat adapters can be found here. For example, to install the Slack chat adapter, run the following command:

npm install hubot-slack --save

Then, create a Hubot service and copy the API token.

Next, install heartbot. While still in the heartbot directory, run:

npm install hubot-heartbot --save
cp node_modules/hubot-heartbot/config.yml heartbot.config.yml

To enable the Heartbot Hubot plugin, add hubot-heartbot to external-scripts.json:

...
  "hubot-youtube",
  "hubot-heartbot"
]

Sign up for forecast.io and copy your API key.

Finally, start Heartbot:

HUBOT_SLACK_TOKEN=slack-token-here HEARTBOT_FORECAST_API_KEY=forecast.io-api-token-here ./bin/hubot -a slack

Configuring Interactions

Heartbot comes with a number of interactions pre-configured. Heartbot's configuration file, heartbot.config.yml, can be found in your Hubot instance's root directory.

---
probability: 0.6
interactions:
    - pattern:
        ...

    - pattern:
        ...

The two main keys in the configuration file are:

probability

A number between 0-1 that specifies the probability of Heartbot responding to a trigger. Setting it to 0 disables all interaction, while setting it to 1 makes Heartbot respond to all interactions at all times. Setting it to .5 would ensure that Heartbot would respond half the time to interactions.

This is done so that Heartbot does not get overly annoying in busy channels/rooms.

In addition, a single interaction's probability can be modified independently of the global probability setting. You can do that by passing a probability key to the interaction.

interactions

A list of interactions that Heartbot should respond to.

An interaction should be written in the following format:

- pattern:
    regex: >-
      ((what|who)('?s| is) |\?)##heartbot##
  event: say
  message: I'm Heartbot, a Hubot integration that is here to bring a little love and joy into the room.
  probability: 1

pattern

The pattern object should include a regex key and, optionally, an options key, which describe the RegEx pattern that should be match in order to trigger the interaction.

  • regex: The text of the regular expression. You can use ##heartbot## in the pattern to match the bot's name, which will be replaced with the bot's name once the interaction is loaded.
  • options: Defaults to i. If specified, it can be a combination of any of the following values: g, i, m, and y. However, in this case, Heartbot would only benefit from the i option, which would make the RegEx pattern case-insensitive. You can find some details on the other options here.

message

The text that the interaction should respond with. This is usually a string, but can be an array of strings out of which a random message is picked depending on whether or not the event supports that, which the three events that Heartbot comes with (in the events directory) do.

There are a number of variables that can be used:

  • $user: The name of the user who triggered the interaction.
  • $room: The room/channel which the user triggered the interaction in.
  • $heartbot: The bot's name.

event

The name of the event that should be called once the interaction is triggered. Heartbot ships with three events (see the events directory):

say

Simply a message that Heartbot should respond with. Other than the variables described above, no additional processing is done.

The say event can accept an optional option:

  • messageType: How to actually respond. Can be either say (the default) or action.
forecast

Fetch the temperature in a specific location and respond with the message. Two additional keys are required:

  • location: An object of the latitude and longitude of the location.
  • units: Which units to use, can be either F or C.

In addition to these two keys, a forecast.io API key is required. You can pass the API key in an environment variable called HEARTBOT_FORECAST_API_KEY.

The forecast event supplies two variables to the message:

  • $temperature: The temperature in the said location.
  • $units: The units used.

For example, to fetch the temperature in Oymyakon, Russia:

- pattern:
    ...
  event: forecast
  message: It could be worse. It’s currently $temperature° $units in Oymyakon, Russia
  location:
    latitude: 63.460833
    longitude: 142.785833
  units: C
giphy

Search Giphy for a random gif based on a specific search query.

The giphy event expects two options:

  • tag: The search query.
  • rating: Defaults to g. Limits search results to those rated y, g, pg, pg-13, or r.

If you are using Heartbot in production, you should pass an API key as the public API key that is used by default is subject to rate limiting and is intended only for development usage.

Please see Giphy API Documentation > Access and API Keys. The API key can be passed using the environment variable HEARTBOT_GIPHY_API_KEY.

- pattern:
    regex: ^puppy me$
  event: giphy
  tag: cute puppy
  message: Here's a puppy: $gif

probability

A single interaction's probability can be overridden to make it different from the global probability value. Simply pass a probability key with the new probability value:

- pattern:
    regex: ^puppy me$
  event: giphy
  tag: cute puppy
  message: Here's a puppy: $gif
  probability: 1

Extending Heartbot

It is possible to write and use custom events. Events are written in CoffeeScript and should export a class with a method called process. The rest is entirely up to you.

The constructor is passed the interaction object from the configuration file.

The process method is called with one argument: msg, an instance of Hubot's Response class. Please see Hubot's official documentation on it.

A few helper functions are included in lib/common.coffee:

applyVariable = (string, variable, value, regexFlags = 'i')

  • string: A string/template which the variable should be added to.
  • variable: The variable's name.
  • value: The variable's value.
  • regexFlags: Defaults to i. The flags that are used to match variable in string.

For example:

string = 'Hello, $user!'

applyVariable string, 'user', 'Jane'
# 'Hello, Jane!'

msgVariables = (message, msg)

  • message: A string/template which the variables should be added to.
  • msg: The msg variable that is passed to the process method.

This function provides a few variables from msg to message.

stringElseRandomKey = (variable)

If variable is a string, it is simply returned back. However, if it is an array, a random item is returned.

regexEscape = (string)

Escape string so that it can safely be used in a RegEx pattern.

More Repositories

1

nginxconfig.io

⚙️ NGINX config generator on steroids 💉
JavaScript
27,244
star
2

doctl

The official command line interface for the DigitalOcean API.
Go
3,155
star
3

godo

DigitalOcean Go API client
Go
1,328
star
4

go-libvirt

Package libvirt provides a pure Go interface for interacting with Libvirt. Apache 2.0 Licensed.
Go
815
star
5

do_user_scripts

Shell
804
star
6

Kubernetes-Starter-Kit-Developers

Hands-on tutorial and Automation stack for an operations-ready DigitalOcean Kubernetes (DOKS) cluster.
HCL
705
star
7

firebolt

Golang framework for streaming ETL, observability data pipeline, and event processing apps
Go
688
star
8

go-qemu

Go packages to interact with QEMU using the QEMU Machine Protocol (QMP). Apache 2.0 Licensed.
Go
684
star
9

do-agent

Collects system metrics from DigitalOcean Droplets
Go
586
star
10

csi-digitalocean

A Container Storage Interface (CSI) Driver for DigitalOcean Block Storage
Go
565
star
11

clusterlint

A best practices checker for Kubernetes clusters. 🤠
Go
536
star
12

vulcan

Vulcan extends Prometheus adding horizontal scalability and long-term storage
Go
531
star
13

digitalocean-cloud-controller-manager

Kubernetes cloud-controller-manager for DigitalOcean (beta)
Go
517
star
14

hacktoberfest

Hacktoberfest - App to manage the annual open-source challenge, used for the 2019 & 2020 seasons.
Ruby
510
star
15

droplet_kit

DropletKit is the official DigitalOcean API client for Ruby.
Ruby
507
star
16

terraform-provider-digitalocean

Terraform DigitalOcean provider
Go
487
star
17

action-doctl

GitHub Actions for DigitalOcean - doctl
JavaScript
454
star
18

ceph_exporter

Prometheus exporter that scrapes meta information about a ceph cluster.
Go
396
star
19

engineering-code-of-conduct

Code of Conduct for DigitalOcean's Engineering Team
289
star
20

go-openvswitch

Go packages which enable interacting with Open vSwitch and related tools. Apache 2.0 Licensed.
Go
282
star
21

kubernetes-sample-apps

Example DigitalOcean Kubernetes workload with service exposed through a DO load-balancer.
Python
252
star
22

marketplace-partners

Image validation, automation, and other tools for DigitalOcean Marketplace Vendors and Custom Image users
Shell
190
star
23

gta

gta: do transitive analysis to find packages whose dependencies have changed
Go
182
star
24

prometheus-client-c

A Prometheus Client in C
C
154
star
25

marketplace-kubernetes

This repository contains the source code and deployment scripts for Kubernetes-based applications listed in the DigitalOcean Marketplace.
Shell
154
star
26

go-smbios

Package smbios provides detection and access to System Management BIOS (SMBIOS) and Desktop Management Interface (DMI) data and structures. Apache 2.0 Licensed.
Go
152
star
27

kartograph

Kartograph makes it easy to generate and convert JSON. It's intention is to be used for API clients.
Ruby
147
star
28

OpenVPN-Pihole

https://marketplace.digitalocean.com/apps/openvpn-pihole
Shell
146
star
29

captainslog

A Syslog Protocol Parser
Go
136
star
30

resource_kit

Resource Kit provides tools to aid in making API Clients. Such as URL resolving, Request / Response layer, and more.
Ruby
134
star
31

go-workers2

better-go-workers
Go
121
star
32

doks-debug

A Docker image with Kubernetes manifests for investigation and troubleshooting.
Dockerfile
109
star
33

droplet-1-clicks

Packer build scripts for DigitalOcean Marketplace 1-clicks.
Shell
105
star
34

supabase-on-do

HCL
98
star
35

openapi

The OpenAPI v3 specification for DigitalOcean's public API.
JavaScript
97
star
36

container-blueprints

DigitalOcean Kubernetes(DOKS) Solution Blueprints
HCL
92
star
37

sample-dockerfile

⛵ App Platform sample Docker application.
Go
90
star
38

DOKS

Managed Kubernetes designed for simple and cost effective container orchestration.
80
star
39

app_action

Deploy to DigitalOcean Container Registry and App Platform
Go
78
star
40

navigators-guide

Book and code examples that help to build infrastructure on DigitalOcean
Shell
76
star
41

do-operator

The Kubernetes Operator for DigitalOcean
Go
76
star
42

pydo

Official DigitalOcean Python Client based on the DO OpenAPIv3 specification
Python
75
star
43

sample-django

Django sample app for DigitalOcean App Platform
Python
74
star
44

logtalez

logtalez is a minimal command line client (and API) for retrieving log streams from the rsyslog logging daemon over zeromq.
Go
73
star
45

do-markdownit

Markdown-It plugin for the DigitalOcean Community.
JavaScript
71
star
46

databases

66
star
47

sample-nodejs

⛵ App Platform sample Node.js application.
JavaScript
60
star
48

debian-sys-maint-roll-passwd

Script to update password for MySQL user "debian-sys-maint"
Shell
58
star
49

sample-nextjs

⛵ App Platform sample Next.js application.
JavaScript
57
star
50

sample-python

⛵ App Platform sample Python application.
Python
52
star
51

vmtop

Real-time monitoring of KVM/Qemu VMs
Python
52
star
52

kubecon-2022-doks-workshop

HCL
48
star
53

sample-flask

Sample Flask Application to be deployed on DigitalOcean's App Platform
HTML
45
star
54

sample-laravel

⛵ App Platform sample Laravel application.
PHP
43
star
55

pgremapper

CLI tool for manipulating Ceph's upmap exception table.
Go
43
star
56

k8s-staticroute-operator

Create static routes for your k8s nodes using CRDs.
Python
42
star
57

sample-functions-nodejs-qrcode

HTML
39
star
58

tos

DigitalOcean's Terms of Service agreement
37
star
59

sample-monorepo

Sample mono repo app (with multiple components) on the DigitalOcean App Platform.
Go
36
star
60

sample-golang

⛵ App Platform sample Golang application.
Go
36
star
61

droplet-agent

Droplet Agent is the daemon that runs on customer droplets to enable some features such as web console access.
Go
36
star
62

openvswitch_exporter

Command openvswitch_exporter implements a Prometheus exporter for Open vSwitch.
Go
32
star
63

sample-php

⛵ App Platform sample PHP application.
PHP
32
star
64

mastodon-on-kubernetes

Setting up Mastodon on DigitalOcean Kubernetes
HCL
30
star
65

sample-html

⛵ App Platform sample HTML application.
HTML
30
star
66

sample-functions-nodejs-helloworld

JavaScript
30
star
67

sample-functions-python-jokes

Python
30
star
68

flipop

Floating IP Controller for Kubernetes
Go
29
star
69

ansible-collection

DigitalOcean Ansible Collection
Python
28
star
70

sample-functions-golang-helloworld

Go
28
star
71

go-metadata

Go client for the metadata API.
Go
27
star
72

sample-react

⛵ App Platform sample React application.
JavaScript
27
star
73

marketplace-pi-hole-vpn

Pi-hole VPN image for Marketplace with Unbound & Wireguard
Shell
26
star
74

omniauth-digitalocean

DigitalOcean OAuth2 Strategy for OmniAuth
Ruby
26
star
75

github-changelog-generator

A tool to generate changelog entries from GitHub repositories.
Go
25
star
76

sample-functions-python-helloworld

Python
22
star
77

terraform-vault-github-oidc

Terraform module to configure Vault for GitHub OIDC authentication from Action runners.
HCL
22
star
78

sample-push-to-deploy-doks

Push-to-deploy example using DOCR and DOKS
Python
21
star
79

netbox-ip-controller

A Kubernetes controller to import the IP addresses and metadata of pods and services into NetBox.
Go
20
star
80

sample-expressjs

⛵ App Platform sample Express.js application.
19
star
81

terraform-provider-sendgrid

Sendgrid Terraform Provider
Go
19
star
82

sample-nuxtjs

⛵ App Platform sample Nuxt.js application.
Vue
19
star
83

sample-vuejs

⛵ App Platform sample Vue.js application.
Vue
17
star
84

production-ready-kubernetes-workshop

The repository for DigitalOcean's Production Ready Kubernetes Workshop
Python
16
star
85

sample-functions-python-twilio-sms

Sending sms via Twilio
Python
16
star
86

sample-rails

⛵ App Platform sample Ruby on Rails application.
Ruby
15
star
87

sample-functions-php-numberstowords

PHP
15
star
88

sample-functions-php-helloworld

A PHP helloworld sample function for Cloud Functions
PHP
14
star
89

sample-hugo

⛵ App Platform sample Hugo application.
14
star
90

github-pr-resource

Github pull request resource for Concourse
Go
13
star
91

sample-functions-python-sendgrid-email

Sending emails via Sendgrid API
Python
13
star
92

icingaweb2-module-netboximport

Icinga2 Director integration for Netbox
PHP
12
star
93

docker-shipit-engine

Docker image for https://github.com/Shopify/shipit-engine
Ruby
11
star
94

sample-functions-golang-presigned-url

Creating a presigned url for DO's Spaces
Go
10
star
95

digitalocean-ceph-lab

Terraform and Ansible automation to provision and configure a Ceph test environment on DigitalOcean.
HCL
10
star
96

k8s-adoption-journey

Hands-on tutorial for going from Day-1 to production on DigitalOcean Kubernetes. Goes with "Kubernetes Adoption Journey" document.
Python
9
star
97

sample-laravel-api

⛵ App Platform sample Laravel API application.
PHP
9
star
98

gnulib

A mirror of the gnulib portability and testing suite for internal builds that use it as a submodule
C
8
star
99

serverless-jamstack

Contains sample code for a serverless Jamstack tutorial published on docs.digitalocean.com
JavaScript
8
star
100

sample-gatsby

⛵ App Platform sample Gatsby application.
CSS
8
star