go-typetalk

module
v2.1.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2019 License: MIT

README

go-typetalk

Build Status Coverage Status Documentation

go-typetalk is a GO client library for accessing the Typetalk API.

Prerequisite

To use this library, you must have a valid client id and client secret provided by Typetalk and register a new client application. Or you can use the Typetalk Token.

Installation

This package can be installed with the go get command:

$ go get github.com/nulab/go-typetalk

Usage

Import

Use v1:

import "github.com/nulab/go-typetalk/typetalk/v1"

Use v2:

import "github.com/nulab/go-typetalk/typetalk/v2"

Use v3:

import "github.com/nulab/go-typetalk/typetalk/v3"
Access APIs using Typetalk Token
package main

import (
	"context"

	"github.com/nulab/go-typetalk/typetalk/v1"
)

func main() {
	client := v1.NewClient(nil)
	client.SetTypetalkToken("yourTypetalkToken")
	ctx := context.Background()
	topicId := 1
	message := "Hello"
	profile, resp, err := client.Messages.PostMessage(ctx, topicId, message, nil)
}
Access APIs using OAuth2 Access Token
package main

import (
	"context"
	"encoding/json"
	"net/http"
	"net/url"

	"github.com/nulab/go-typetalk/typetalk/v1"
	"golang.org/x/oauth2"
)

type AccessToken struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

func main() {
	form := url.Values{}
	form.Add("client_id", "yourClientId")
	form.Add("client_secret", "yourClientSecret")
	form.Add("grant_type", "client_credentials")
	form.Add("scope", "topic.read,topic.post,topic.write,topic.delete,my")
	oauth2resp, err := http.PostForm("https://typetalk.com/oauth2/access_token", form)
	if err != nil {
		print("Client Credential request returned error")
	}
	v := &AccessToken{}
	json.NewDecoder(oauth2resp.Body).Decode(v)

	tc := oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: v.AccessToken},
	))

	client := v1.NewClient(tc)
	profile, resp, err := client.Accounts.GetMyProfile(context.Background())
}

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

Directories

Path Synopsis
example
typetalk
v1
v2
v3
v4
v5

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL