Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

go-botmetrics

go-botmetrics is a Go client to the BotMetrics service which lets you collect & analyze metrics for your bot.

Build Status

Setting your API Host (for Self-Hosting)

If you are using your own self-hosted version of Botmetrics, remember to set the BOTMETRICS_API_HOST environment variable to your host (If you have hosted your Botmetrics instance at https://my-botmetrics-instance.herokuapp.com, set BOTMETRICS_API_HOST to https://my-botmetrics-instance.herokuapp.com.

Usage (Facebook)

Register your Facebook bot with Botmetrics. Once you have done so, navigate to "Bot Settings" and find out your Bot ID and API Key.

With that, you can initialize a BotmetricsClient:

import "github.com/botmetrics/go-botmetrics"

client := botmetrics.NewBotmetricsClient("api-key", "bot-id")

Alternatively, you can set the following ENV variables

  • ENV['BOTMETRICS_API_KEY']
  • ENV['BOTMETRICS_BOT_ID']

and initialize a BotmetricsClient with the default ENV variables:

import "github.com/botmetrics/go-botmetrics"

client := botmetrics.NewBotmetricsClient()

track

Call the track API in the webhook receiver that handles all of your Facebook messages.

For e.g.

// In your Go Request handler, make a call to client.Track
// with the request body
import "github.com/botmetrics/go-botmetrics"

http.HandleFunc("/webhooks", func(w http.ResponseWriter, r *http.Request) {
	postBody, err := ioutil.ReadAll(r.Body)

	if err != nil {
		panic(err)
	}

	client, err := botmetrics.NewBotMetricsClient()
	if err == nil {
		client.Track(postBody)
	}
})

Usage (Kik)

Register your Kik bot with Botmetrics. Once you have done so, navigate to "Bot Settings" and find out your Bot ID and API Key.

With that, you can initialize a BotmetricsClient:

import "github.com/botmetrics/go-botmetrics"

client := botmetrics.NewBotmetricsClient("api-key", "bot-id")

Alternatively, you can set the following ENV variables

  • ENV['BOTMETRICS_API_KEY']
  • ENV['BOTMETRICS_BOT_ID']

and initialize a BotmetricsClient with the default ENV variables:

import "github.com/botmetrics/go-botmetrics"

client := botmetrics.NewBotmetricsClient()

track

Call the track API in the webhook receiver that handles all of your Kik messages.

For e.g.

// In your Go Request handler, make a call to client.Track
// with the request body
import "github.com/botmetrics/go-botmetrics"

http.HandleFunc("/webhooks", func(w http.ResponseWriter, r *http.Request) {
	postBody, err := ioutil.ReadAll(r.Body)

	if err != nil {
		panic(err)
	}

	client, err := botmetrics.NewBotMetricsClient()
	if err == nil {
		client.Track(postBody)
	}
})

Usage (Slack)

Log in to your BotMetrics account, navigate to "Bot Settings" and find out your Bot ID and API Key.

With that, you can initialize a BotmetricsClient:

import "github.com/botmetrics/go-botmetrics"

client := botmetrics.NewBotmetricsClient("api-key", "bot-id")

Alternatively, you can set the following ENV variables

  • ENV['BOTMETRICS_API_KEY']
  • ENV['BOTMETRICS_BOT_ID']

and initialize a BotmetricsClient with the default ENV variables:

import "github.com/botmetrics/go-botmetrics"

client := botmetrics.NewBotmetricsClient()

RegisterBot

With a BotmetricsClient instance, every time you create a new Slack Bot (in the OAuth2 callback), and assuming the bot token you received as part of the OAuth2 callback is bot-token, you can make the following call:

import "github.com/botmetrics/go-botmetrics"

client := botmetrics.NewBotmetricsClient("api-key", "bot-id")
client.RegisterBot('bot-token', 0)

Retroactive Registration

If you created your bot in the past, you can pass in created_at with the UNIX timestamp of when your bot was created, like so:

import "github.com/botmetrics/go-botmetrics"

client := botmetrics.NewBotmetricsClient("api-key", "bot-id")
client.RegisterBot('bot-token', 1462318092)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/botmetrics/go-botmetrics. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

About

Go Client for the Botmetrics API

Resources

Releases

No releases published

Packages

No packages published