Experimental Slack SDK in Go
This is an experimental Slack API client library.
Getting Started
Start a New Project
go mod init example.com/hello-slack
go get github.com/seratch/go-slack-sdk-experimental/webapi
Place main.go
package main
import (
"encoding/json"
"fmt"
"github.com/seratch/go-slack-sdk-experimental/webapi"
"github.com/seratch/go-slack-sdk-experimental/webapi/chat_postMessage"
"io/ioutil"
"net/url"
"os"
)
func main() {
token := os.Getenv("SLACK_BOT_TOKEN")
client := webapi.NewClient(&token)
data := url.Values{}
data.Set("text", "Hi there!")
data.Set("channel", "#random")
resp, err := client.CallApi(chat_postMessage.ApiMethod, data)
if err != nil {
fmt.Println(fmt.Sprintf("HTTP error: %s", err))
return
}
bytes, _ := ioutil.ReadAll(resp.Body)
body, _ := chat_postMessage.UnmarshalChatPostMessage(bytes)
bytesAgain, _ := json.Marshal(body)
fmt.Println(string(bytesAgain))
if !*body.Ok {
fmt.Println(fmt.Sprintf("Slack error: %s", *body.Error))
}
}
Run the App
export SLACK_BOT_TOKEN=xoxb-***
go run main.go
License
The MIT License