github.com/line/line-bot-sdk-go/v7@v7.21.0/README.md (about) 1 # LINE Messaging API SDK for Go 2 3 [](https://github.com/line/line-bot-sdk-go/actions) 4 [](https://codecov.io/gh/line/line-bot-sdk-go) 5 [](http://godoc.org/github.com/line/line-bot-sdk-go/linebot) 6 [](https://goreportcard.com/report/github.com/line/line-bot-sdk-go) 7 8 9 ## Introduction 10 The LINE Messaging API SDK for Go makes it easy to develop bots using LINE Messaging API, and you can create a sample bot within minutes. 11 12 ## Documentation 13 14 See the official API documentation for more information. 15 16 - English: https://developers.line.biz/en/docs/messaging-api/overview/ 17 - Japanese: https://developers.line.biz/ja/docs/messaging-api/overview/ 18 19 ## Requirements 20 21 This library requires Go 1.11 or later. 22 23 ## Installation ## 24 25 ```sh 26 $ go get -u github.com/line/line-bot-sdk-go/v7/linebot 27 ``` 28 29 ## Configuration ## 30 31 ```go 32 import ( 33 "github.com/line/line-bot-sdk-go/v7/linebot" 34 ) 35 36 func main() { 37 bot, err := linebot.New("<channel secret>", "<channel access token>") 38 ... 39 } 40 41 ``` 42 43 ### Configuration with http.Client ### 44 45 ```go 46 client := &http.Client{} 47 bot, err := linebot.New("<channel secret>", "<channel access token>", linebot.WithHTTPClient(client)) 48 ... 49 ``` 50 51 ## How to start ## 52 53 The LINE Messaging API uses the JSON data format. 54 ```ParseRequest()``` will help you to parse the ```*http.Request``` content and return a slice of Pointer point to Event Object. 55 56 ```go 57 events, err := bot.ParseRequest(req) 58 if err != nil { 59 // Do something when something bad happened. 60 } 61 ``` 62 63 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``` 64 65 ```go 66 for _, event := range events { 67 if event.Type == linebot.EventTypeMessage { 68 // Do Something... 69 } 70 } 71 ``` 72 73 ### Receiver ### 74 75 To send a message to a user, group, or room, you need either an ID 76 77 ```go 78 userID := event.Source.UserID 79 groupID := event.Source.GroupID 80 RoomID := event.Source.RoomID 81 ``` 82 83 or a reply token. 84 85 ```go 86 replyToken := event.ReplyToken 87 ``` 88 89 ### Create message ### 90 91 The LINE Messaging API provides various types of message. To create a message, use ```New<Type>Message()```. 92 93 ```go 94 leftBtn := linebot.NewMessageAction("left", "left clicked") 95 rightBtn := linebot.NewMessageAction("right", "right clicked") 96 97 template := linebot.NewConfirmTemplate("Hello World", leftBtn, rightBtn) 98 99 message := linebot.NewTemplateMessage("Sorry :(, please update your app.", template) 100 ``` 101 102 ### Send message ### 103 104 With an ID, you can send message using ```PushMessage()``` 105 106 ```go 107 var messages []linebot.SendingMessage 108 109 // append some message to messages 110 111 _, err := bot.PushMessage(ID, messages...).Do() 112 if err != nil { 113 // Do something when some bad happened 114 } 115 ``` 116 117 With a reply token, you can reply to messages using ```ReplyMessage()``` 118 119 ```go 120 var messages []linebot.SendingMessage 121 122 // append some message to messages 123 124 _, err := bot.ReplyMessage(replyToken, messages...).Do() 125 if err != nil { 126 // Do something when some bad happened 127 } 128 ``` 129 130 ## Help and media 131 132 FAQ: https://developers.line.biz/en/faq/ 133 134 Community Q&A: https://www.line-community.me/questions 135 136 News: https://developers.line.biz/en/news/ 137 138 Twitter: @LINE_DEV 139 140 141 ## Versioning 142 This project respects semantic versioning. 143 144 See http://semver.org/ 145 146 147 ## Contributing 148 149 Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution. 150 151 152 ## License 153 154 ``` 155 Copyright (C) 2016 LINE Corp. 156 157 Licensed under the Apache License, Version 2.0 (the "License"); 158 you may not use this file except in compliance with the License. 159 You may obtain a copy of the License at 160 161 http://www.apache.org/licenses/LICENSE-2.0 162 163 Unless required by applicable law or agreed to in writing, software 164 distributed under the License is distributed on an "AS IS" BASIS, 165 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 166 See the License for the specific language governing permissions and 167 limitations under the License. 168 ```