golineworks

module
v0.0.0-...-cb3295b Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT

README

golineworks

Send and receive LINE Works messages in Go.

Supported APIs

  • Sending content
  • Receiving content (utils)
  • Download user content

Supported Contents

  • Text
  • Link
  • Image
  • Button
  • Sticker

Sending message

func main() {
	apiId := "..."
	botId := "..."
	serverApiConsumerKey := "..."
	serverListId := "..."
	privateKey := []byte(`-----BEGIN PRIVATE KEY-----`
	...
	-----END PRIVATE KEY-----`)

	con := api.NewApiDefault(apiId, botId, serverApiConsumerKey, serverListId, privateKey)

	/*
	buttons := []interface{}{
		api.NewButtonActionMessage("...", "..."),
		api.NewButtonActionUri("...", "https://.../..."),
	}
	*/

	req := api.Request{
		AccountId: "...",
		//Content: api.NewLinkContent("...", "...", "https://..."),
		//Content: api.NewImageContent("https://.../....png", "https://.../....png"),
		//Content: api.NewButtonContent("...", buttons),
		Content: api.NewTextContent("..."),
	}

	body, err := con.SendRequest(req)

	fmt.Println(err)
	fmt.Println(body)
}

Callback utils

func Callback(w http.ResponseWriter, r *http.Request) {
   obj, err := callback.Parse(r.Body)
   if err != nil {
   	fmt.Println("parse error")
   	return
   }

   fmt.Printf("Account: %s", obj.Source.AccountId)
}

Download user content using resourceId of image content

func DownloadToFile(resourceId string) {
	con := api.NewApiDefault(API_ID, BOT_ID, SERVER_API_CONSUMER_KEY, server_list_id, privateKey)
	res, err := con.GetContent(ResourceId)

	fo, err := os.Create("img.jpg")
	if err != nil {
		return
	}
	defer fi.Close()

	fo.Write(res)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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