go-botmetrics is a Go client to the BotMetrics service which lets you collect & analyze metrics for your bot.
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
.
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()
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)
}
})
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()
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)
}
})
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()
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)
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)
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.
The gem is available as open source under the terms of the MIT License.