Programmatically
The preferred way to use this SDK is programmatically; this consists of 4 steps:
- Configure the calendar provider
- Configure the chat client
- Configure the application, with the calendar provider, calendar ID, and other settings
- Run the application
package main
import (
"context"
rcs "github.com/bnjns/rich-chat-statuses"
"github.com/bnjns/rich-chat-statuses/calendars/google"
"github.com/bnjns/rich-chat-statuses/clients/slack"
"os"
)
func main() {
ctx := context.Background()
// 1. Create the calendar provider, here we use Google
credentialsJson := os.Getenv("GOOGLE_CREDENTIALS_JSON")
calendar, err := google.New(ctx, google.WithCredentialsJson(credentialsJson))
if err != nil {
panic(err)
}
// 2. Configure the chat client, here we use Slack
slackClient := slack.New(os.Getenv("SLACK_TOKEN"))
// 3. Create the application
app, err := rcs.New(
rcs.WithCalendarProvider(calendar),
rcs.WithCalendarId(os.Getenv("CALENDAR_ID")),
)
// 4. Run the application
if err := app.Execute(ctx, slackClient); err != nil {
panic(err)
}
}
Available settings
WithCalendarProvider
: configures the calendar provider used to fetch the active eventsWithCalendarId
: configures the ID of the calendar the events are fetched fromWithLogHandler
: configures the log handler for the app, clients and calendar provider (defaults tologfmt
)WithLogLevel
: configures the log level for the app, clients and calendar provider (defaults toINFO
)WithStatusPresets
: configures the status presets
Multiple clients
You can run the same application on multiple chat clients if you wish. At the moment, this needs to be manually executed sequentially.
func main() {
// Steps 1 and 3 omitted for brevity
// Create clients
firstClient := slack.New(os.Getenv("SLACK_TOKEN_FIRST"))
secondClient := slack.New(os.Getenv("SLACK_TOKEN_SECOND"))
// Run the application on each client in turn
if err := app.Execute(ctx, firstClient); err != nil {
panic(err)
}
if err := app.Execute(ctx, secondClient); err != nil {
panic(err)
}
}