Git Product home page Git Product logo

line-bot-sdk-go's Introduction

line-bot-sdk-go

Build Status

Go SDK for the LINE Messaging API

About LINE Messaging API

See the official API documentation for more information.

English: https://developers.line.me/en/docs/messaging-api/reference/
Japanese: https://developers.line.me/ja/docs/messaging-api/reference/

Installation

$ go get github.com/line/line-bot-sdk-go/linebot

Configuration

import (
	"github.com/line/line-bot-sdk-go/linebot"
)

func main() {
	bot, err := linebot.New("<channel secret>", "<channel access token>")
	...
}

Configuration with http.Client

	client := &http.Client{}
	bot, err := linebot.New("<channel secret>", "<channel accsss token>", linebot.WithHTTPClient(client))
	...

How to start

The LINE Messaging API uses the JSON data format. ParseRequest() will help you to parse the *http.Request content and return a slice of Pointer point to Event Object.

	events, err := bot.ParseRequest(req)
	if err != nil {
		// Do something when something bad happened.
	}

The LINE Messaging API defines 7 types of event - EventTypeMessage, EventTypeFollow, EventTypeUnfollow, EventTypeJoin, EventTypeLeave, EventTypePostback, EventTypeBeacon. You can check the event type by using event.Type

	for _, event := range events {
		if event.Type == linebot.EventTypeMessage {
			// Do Something...
		}
	}

Receiver

To send a message to a user, group, or room, you need either an ID

	userID := event.Source.UserID
	groupID := event.Source.GroupID
	RoomID := event.Source.RoomID

or a reply token.

	replyToken := event.ReplyToken

Create message

The LINE Messaging API provides various types of message. To create a message, use New<Type>Message().

	leftBtn := linebot.NewMessageTemplateAction("left", "left clicked")
	rightBtn := linebot.NewMessageTemplateAction("right", "right clicked")

	template := linebot.NewConfirmTemplate("Hello World", leftBtn, rightBtn)

	message := linebot.NewTemplateMessage("Sorry :(, please update your app.", template)

Send message

With an ID, you can send message using PushMessage()

	var messages []linebot.Message

	// append some message to messages

	_, err := bot.PushMessage(ID, messages...).Do()
	if err != nil {
		// Do something when some bad happened
	}

With a reply token, you can reply to messages using ReplyMessage()

	var messages []linebot.Message

	// append some message to messages

	_, err := bot.ReplyMessage(replyToken, messages...).Do()
	if err != nil {
		// Do something when some bad happened
	}

Requirements

This library requires Go 1.6 or later.

LICENSE

See LICENSE.txt

line-bot-sdk-go's People

Contributors

appleboy avatar candy02058912 avatar clsung avatar guitarsucks avatar k2wanko avatar kawaken avatar ken2mer avatar kwmt avatar m90 avatar mokejp avatar moznion avatar nkjm avatar puhsiu avatar sugyan avatar zaneli avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.