22
33[ ![ Build Status] ( https://travis-ci.org/line/line-bot-sdk-go.svg?branch=master )] ( https://travis-ci.org/line/line-bot-sdk-go )
44
5- SDK of the LINE BOT API Trial for Go
5+ Go SDK for the LINE Messaging API
6+
7+
8+ ## About LINE Messaging API
9+
10+ Please refer to the official api documents for details.
11+
12+ en: https://devdocs.line.me/en/
13+
14+ ja: https://devdocs.line.me/ja/
15+
616
717## Installation ##
818
@@ -18,7 +28,7 @@ import (
1828)
1929
2030func main () {
21- bot , err := linebot.NewClient (<Channel ID>, " <Channel Secret >" , " <MID >" )
31+ bot , err := linebot.New ( " <channel secret >" , " <channel access token >" )
2232 ...
2333}
2434
@@ -28,176 +38,14 @@ func main() {
2838
2939``` go
3040 client := &http.Client {}
31- bot , err := linebot.NewClient (<Channel ID >, " <Channel Secret >" , " <MID >" , linebot.WithHTTPClient (client))
41+ bot , err := linebot.New ( " <channel secret >" , " <channel accsss token >" , linebot.WithHTTPClient (client))
3242 ...
3343```
3444
35- ## Usage ##
36-
37- ### Sending messages ###
38-
39- Send a text message, image, video, audio, location, or sticker to the mids.
40-
41- - [ https://developers.line.me/bot-api/api-reference#sending_message ] ( https://developers.line.me/bot-api/api-reference#sending_message )
42-
43- ``` go
44- // send text
45- res , err := bot.SendText ([]string {" <target user's MID>" }, " Hello, world!" )
46-
47- // send image
48- res , err := bot.SendImage ([]string {" <target user's MID>" }, " http://example.com/image.jpg" , " http://example.com/image_preview.jpg" )
49-
50- // send video
51- res , err := bot.SendVideo ([]string {" <target user's MID>" }, " http://example.com/video.mp4" , " http://example.com/image_preview.jpg" )
52-
53- // send audio
54- res , err := bot.SendAudio ([]string {" <target user's MID>" }, " http://example.com/audio.mp3" , 2000 )
55-
56- // send location
57- res , err := bot.SendLocation ([]string {" <target user's MID>" }, " location label" , " tokyo shibuya-ku" , 35.661777 , 139.704051 )
58-
59- // send sticker
60- res , err := bot.SendSticker ([]string {" <target user's MID>" }, 1 , 1 , 100 )
61- ```
62-
63- ### Sending multiple messages ###
64-
65- The ` multiple_message ` method allows you to use the _ Sending multiple messages API_ .
66-
67- - [ https://developers.line.me/bot-api/api-reference#sending_multiple_messages ] ( https://developers.line.me/bot-api/api-reference#sending_multiple_messages )
68-
69- ``` go
70- res , err := bot.NewMultipleMessage ().
71- AddText (" Hello," ).
72- AddText (" world!" ).
73- AddImage (" http://example.com/image.jpg" , " http://example.com/image_preview.jpg" )
74- AddVideo (" http://example.com/video.mp4" , " http://example.com/image_preview.jpg" )
75- AddAudio (" http://example.com/audio.mp3" , 2000 )
76- AddLocation (" Location label" , " tokyo shibuya-ku" , 35.61823286112982 , 139.72824096679688 ).
77- AddSticker (1 , 1 , 100 ).
78- Send ([]string {" <target user's MID>" })
79- ```
80-
81- ### Sending rich messages ###
82-
83- The ` rich_message ` method allows you to use the _ Sending rich messages API_ .
84-
85- - [ https://developers.line.me/bot-api/api-reference#sending_rich_content_message ] ( https://developers.line.me/bot-api/api-reference#sending_rich_content_message )
86-
87- ``` go
88- res , err := bot.NewRichMessage (1040 ).
89- SetAction (" MANGA" , " manga" , " https://store.line.me/family/manga/en" ).
90- SetListener (" MANGA" , 0 , 0 , 520 , 520 ).
91- SetAction (" MUSIC" , " music" , " https://store.line.me/family/music/en" ).
92- SetListener (" MUSIC" , 520 , 0 , 520 , 520 ).
93- Send ([]string {" <target user's MID>" }, " https://example.com/rich-image/foo" , " This is a alt text." )
94- ```
95-
96- ### Receiving messages ###
45+ ## Requirements
9746
98- The following utility method allows you to easily process messages sent from the BOT API platform via a Callback URL .
47+ This library requires Go 1.6 or later .
9948
100- - [ https://developers.line.me/bot-api/api-reference#receiving_messages ] ( https://developers.line.me/bot-api/api-reference#receiving_messages )
49+ ## LICENSE
10150
102- ``` go
103- http.HandleFunc (" /callback" , func (w http.ResponseWriter , req *http.Request ) {
104- received , err := bot.ParseRequest (req)
105- if err != nil {
106- if err == linebot.ErrInvalidSignature {
107- w.WriteHeader (400 )
108- } else {
109- w.WriteHeader (500 )
110- }
111- return
112- }
113- for _ , result := range received.Results {
114- content := result.Content ()
115- if content != nil && content.IsMessage && content.ContentType == linebot.ContentTypeText {
116- text , err := content.TextContent ()
117- _ , err := bot.SendText ([]string {content.From }, " OK " + text.Text )
118- if err != nil {
119- log.Println (err)
120- }
121- }
122- }
123- })
124- if err := http.ListenAndServe (" :8080" , nil ); err != nil {
125- log.Fatal (err)
126- }
127- ```
128-
129- ### Getting message content ###
130-
131- Retrieve the original file which was sent by user.
132-
133- - [ https://developers.line.me/bot-api/api-reference#getting_message_content ] ( https://developers.line.me/bot-api/api-reference#getting_message_content )
134-
135- ``` go
136- http.HandleFunc (" /callback" , func (w http.ResponseWriter , req *http.Request ) {
137- ...
138- for _ , result := range received.Results {
139- content := result.Content ()
140- if content != nil && content.IsMessage && content.ContentType == linebot.ContentTypeImage {
141- res , err := bot.GetMessageContent (content)
142- if err != nil {
143- return
144- }
145- defer res.Content .Close ()
146- image , err := jpeg.Decode (res.Content )
147- if err != nil {
148- return
149- }
150- log.Printf (" image %v " , image.Bounds ())
151- }
152- }
153- })
154- ```
155-
156- ### Getting previews of message content ###
157-
158- Retrieve the preview image file which was sent by user.
159-
160- - [ https://developers.line.me/bot-api/api-reference#getting_message_content_preview ] ( https://developers.line.me/bot-api/api-reference#getting_message_content_preview )
161-
162- ``` go
163- http.HandleFunc (" /callback" , func (w http.ResponseWriter , req *http.Request ) {
164- ...
165- for _ , result := range received.Results {
166- content := result.Content ()
167- if content != nil && content.IsMessage && content.ContentType == linebot.MessageContentTypeImage {
168- res , err := bot.GetMessageContentPreview (content)
169- if err != nil {
170- return
171- }
172- defer res.Content .Close ()
173- image , err := jpeg.Decode (res.Content )
174- if err != nil {
175- return
176- }
177- log.Printf (" image %v " , image.Bounds ())
178- }
179- }
180- })
181- ```
182-
183- ### Getting user profile information ###
184-
185- You can retrieve the user profile information by specifying the mid.
186-
187- - [ https://developers.line.me/bot-api/api-reference#getting_user_profile_information ] ( https://developers.line.me/bot-api/api-reference#getting_user_profile_information )
188-
189- ``` go
190- http.HandleFunc (" /callback" , func (w http.ResponseWriter , req *http.Request ) {
191- ...
192- for _ , result := range received.Results {
193- content := result.Content ()
194- if content != nil {
195- result , err := bot.GetUserProfile ([]string {content.From })
196- if err != nil {
197- return
198- }
199- log.Printf (" profile: %v " , result)
200- }
201- }
202- })
203- ```
51+ See LICENSE.txt
0 commit comments