line / line-bot-sdk-go Goto Github PK
View Code? Open in Web Editor NEWLINE Messaging API SDK for Go
Home Page: https://developers.line.biz/en/docs/messaging-api/overview/
License: Apache License 2.0
LINE Messaging API SDK for Go
Home Page: https://developers.line.biz/en/docs/messaging-api/overview/
License: Apache License 2.0
Hello! I read "https://github.com/line/line-bot-sdk-go/blob/master/examples/kitchensink/server.go"
has
linebot.NewImagemapMessage(
app.appBaseURL+"/static/rich",
"Imagemap alt text",
linebot.ImagemapBaseSize{1040, 1040},
linebot.NewURIImagemapAction("https://store.line.me/family/manga/en", linebot.ImagemapArea{0, 0, 520, 520}),
linebot.NewURIImagemapAction("https://store.line.me/family/music/en", linebot.ImagemapArea{520, 0, 520, 520}),
linebot.NewURIImagemapAction("https://store.line.me/family/play/en", linebot.ImagemapArea{0, 520, 520, 520}),
linebot.NewMessageImagemapAction("URANAI!", linebot.ImagemapArea{520, 520, 520, 520}),
),
I know app.appBaseURL+"/static/rich"
is JPG or PNG file path.
But how can I use ? filename set index.jpg
in app.appBaseURL+"/static/rich"
path???
or any file name?
or app.appBaseURL+"/static/rich/xxx"
(xxx is int)
or ?????
I need cancel or timeout process.
I think preferable to use the Context function as method chain, because I reuse client.
bot.Context(ctx).SendMessage(...)
I have changed code. k2wanko/line-bot-sdk-go@101c0f4
At first, [message.go] doesn't have [MessageTypeFile MessageType = "file"] in MessageType constants.
And MarshalJSON method in [event.go] doesn't have case with file message.
So, linebot can't parse the event of message with file type.
https://github.com/line/line-bot-sdk-go/blob/master/examples/echo_bot/server.go
これをmain.goにして、
godepも行い、HEROKUにpushいたしました。
os.Getenv("CHANNEL_SECRET"),
os.Getenv("CHANNEL_TOKEN"),
これらのコードの対応のためにBUISINESS CENTERの自分の設定を行った。
heroku config:set CHANNEL_SECRET=xxxx
heroku config:set CHANNEL_TOKEN=xxxx
LINEの管理画面ではWebhook URLには、
https://アカウント.herokuapp.com:443/callback
を設定済み。
heroku logs --tail
は問題なし。
MarshalJSON has not been implemented in the Event struct.
cannot unmarshal string into Go value of type int64
When we create the new tag, we must update linebot/version.go
too.
https://github.com/line/line-bot-sdk-go/blob/master/linebot/version.go
ref:
https://devdocs.line.me/en/#get-group-room-member-ids
It would be nice the APIs take care of the continuationToken part and return a plain array.
We have released imageAspectRatio, imageSize, and imageBackgroundColor fields for Buttons and Carousel template messages. Using these fields, you can configure the aspect ratio, size, and background color for images used in template messages. For more information, see the reference documentation below.
Hi, I am starting using Line Bot SDK, I want to send message to all Bot's friend. I know that webhook can know IDs of all Bot's friend. Is there any example?
Can't build used the golang.org/x/net/context
in application.
$ goapp version
go version go1.6.2 (appengine-1.9.40) darwin/amd64
$ goapp serve
INFO 2016-09-29 08:49:52,683 devappserver2.py:769] Skipping SDK update check.
INFO 2016-09-29 08:49:52,731 api_server.py:205] Starting API server at: http://localhost:62372
INFO 2016-09-29 08:49:52,735 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2016-09-29 08:49:52,739 admin_server.py:116] Starting admin server at: http://localhost:8000
/usr/local/Cellar/app-engine-go-64/1.9.40/share/app-engine-go-64/google/appengine/tools/devappserver2/mtime_file_watcher.py:115: UserWarning: There are too many files in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
'There are too many files in your application for '
ERROR 2016-09-29 08:49:53,989 go_runtime.py:181] Failed to build Go application: (Executed command: /usr/local/Cellar/app-engine-go-64/1.9.40/share/app-engine-go-64/goroot/bin/go-app-builder -app_base /Users/kazu/src/github.com/k2wanko/linebot-example -arch 6 -dynamic -goroot /usr/local/Cellar/app-engine-go-64/1.9.40/share/app-engine-go-64/goroot -nobuild_files ^^$ -unsafe -gopath /Users/kazu -print_extras_hash app.go)
2016/09/29 17:49:53 go-app-builder: Failed parsing input: package "golang.org/x/net/context" is imported from multiple locations: "/Users/kazu/src/golang.org/x/net/context" and "/Users/kazu/src/github.com/line/line-bot-sdk-go/linebot/vendor/golang.org/x/net/context"
remove linebot/vendor
dir.
because golang.org/x/net/context is supported 1.6, 1.7.
In bot API v1 we can get following sticker info.
{ ... "STKVER": "100", "STKID": "1", "STKPKGID": "1" }
But in v2 it only has stickerId
and packageId
from webhooks event.
{ ... "packageId": "1", "stickerId": "1" }
Could you please tell me how to get the version of sticker sent by user?
Because you have a reissuing-access-tokens API for this, I just wonder if you have a plan to let robot can refresh access token by itself before the token is expired.
If you currently install the package in a Go 1.11 module aware environment, the existing git tags will be ignored as they are expected to start with a v
, i.e. 3.0.0
should be v3.0.0
instead: https://github.com/golang/go/wiki/Modules#modules
Is it possible to start tagging the releases in this way, so that it can be properly consumed as a module as well?
https://developers.line.me/en/news/tags/messaging-api/
https://developers.line.me/en/reference/messaging-api/#imagemap-message
We need to support new fields.
If we don't need any code modification in SDK, please add exaample code in kitchensink.
I am dealing with the current scenario: I am building a proxy that connects multiple messenger services including LINE to an NLP backend (api.ai in that case). For some messages the backend will send something called "custom payload" which is basically a messenger specific JSON string that could be passed through to the messenger without touching.
When using package linebot
I will unfortunately have to deparse this Message and construct a new Message (which ends up being the very same) using the supplied methods, which works but is very tedious.
The easiest option would be if I could simply implement interfaces like Message
myself. This is not possible due to the fact that the library attaches empty, invisible methods like message()
or template()
to these interfaces. The fact that they are lowercased/invisible currently makes it impossible to have anything outside of package linebot
implement these interfaces.
Is there any reason this is being done? Would you accept a PR (basically consisting of this commit) that changes the visibility of these interface members, thus allowing 3rd parties to implement the libraries interfaces?
Because I use Line-Go-Bot SDK, so I file issue here.
I find the Line Server is not provide expect callback for operation (expecially on opType=4
(Added as friend))
When I try to get opType
message on JSON, I get as follow:
{
"result": [
{
"content": {
"params": [
"XXX",
null,
null
],
"message": null,
"reqSeq": 0,
"revision": 932,
"opType": 4
},
"createdTime": 1462860363348,
"eventType": "138311609100106403",
"from": "XXX",
"fromChannel": 1341301815,
"id": "SOME_ID",
"to": [
"MSGID"
],
"toChannel": 1462189304
}
]
}
It missing some data under content
so I cannot get any From
information by using result.Content()
also content.OperationContent()
.
Here is example from Line Document.
{"result":[
{
"from":"u2ddf2eb3c959e561f6c9fa2ea732e7eb8",
"fromChannel":1341301815,
"to":["u0cc15697597f61dd8b01cea8b027050e"],
"toChannel":1441301333,
"eventType":"138311609000106303",
"id":"ABCDEF-12345678901",
"content": {
"location":null,
"id":"325708",
"contentType":1,
"from":"uff2aec188e58752ee1fb0f9507c6529a",
"createdTime":1332394961610,
"to":["u0a556cffd4da0dd89c94fb36e36e1cdc"],
"toType":1,
"contentMetadata":null,
"text":"Hello, BOT API Server!"
}
},
...
]}
What I should expect is from
, id
, to
under content
but we could not get from Line Server callback.
The only way I get user information from Operation Callback is result.RawContent.Params[0]
and I don't think it is expected by document.
Please let me know if you need any more detail.
https://developers.line-beta.biz/en/reference/messaging-api/#spacer
by default size of spacer is md
when use
&SpacerComponent{ Type: FlexComponentTypeSpacer }
but request body sent
{"type":"spacer","size":""}
Hi. I want to use NewButtonsTemplate() without thumbnail. I heard other language SDK support without thumbnail. Can you support? Thank you!
APIError 400 A message (messages[0]) in the request body is invalid
[template[@type=buttons].thumbnailImageUrl] must be non-empty text
[template[@type=buttons].thumbnailImageUrl] invalid uri scheme
Hi, I not sure if this is the right platform for me to voice this problem. I used Golang line-bot-sdk-go (Messaging API) send audio to my LINE app through a server (Apache server). But my LINE phone app (android) can not play the audio with error message: "Unknown Error. Please wait a moment and try again." From the Apache SSL log, Apache server replied 400 response code which is bad request. It seem like the LINE audio retrieval code can not establish a proper TLS connection with my Apache server. I also tried replace my Apache server with Golang server (HTTP/1.1 and HTTP2) also can not get a proper connection with the audio request where the Golang ServeHTTP(http.ResponseWriter, *http.Request) is never get call though the TCP connection is there. The audio file I sent actually created from my LINE app which received by my Golang application. Note: the path that I sent using the Messaging API is a correct path because simply using Chrome/curl I can get the audio file with 200 response code. And I don't think is the audio file content issue also because the HTTP connection not reach the code opening the audio file.
I mentioned only audio attachment because image and video attachment both successfully sent to my LINE app. If I am in the wrong place to ask question on this problem then you can point me the right place to do so?
When receiving a message from a room, only the room ID is given as the source of the message. How do I look up the user ID of the sender?
README.md example
var messages []linebot.Message
// append some message to messages
_, err := bot.PushMessage(ID, messages...).Do()
if err != nil {
// Do something when some bad happened
}
failed, output error
cannot use messages (type []linebot.Message) as type []linebot.SendingMessage in argument to bot.PushMessage
This line seem to have typo:
line-bot-sdk-go/linebot/response.go
Line 28 in 3284ab8
Hi,
I can get the event.Source.UserID
from this example but got the following message using PushMessage
func.
if _, err = bot.PushMessage(event.Source.UserID, linebot.NewTextMessage(message.Text)).Do(); err != nil {
log.Print(err)
}
Error Message: linebot: APIError 403 Access to this API is not available for your account
Any thoughts about this issue? Thanks.
I use golang/dep to get line-bot-sdk-go package.
My Download version is only 1.0.0, not having new function that having ImageCarouselTemplate, DatetimePickerTemplateAction etc.
Have any way to use latest version on using dep or glide package manager?
when use {flex: 0} in any component of flex message
flex: 0
not found in request body
because in case marshalJSON of int omitempty
I always get ErrInvalidSignature. I not sure what I can provide but here is a sample of the failure:
Receiving a message of 'Oiii':
{"result":[{"content":{"toType":1,"createdTime":1462516912667,"from":"u6c618ac3c60c51d4f095afaf45c66613","location":null,"id":"4275142935574","to":["u847398b275fbc83c492eb7a21f26bd94"],"text":"Oiii","contentMetadata":{"AT_RECV_MODE":"2","SKIP_BADGE_COUNT":"true"},"deliveredTime":0,"contentType":1,"seq":null},"createdTime":1462516912718,"eventType":"138311609000106303","from":"u206d25c2ea6bd87c17655609a1c37cb8","fromChannel":1341301815,"id":"WB1519-3426467455","to":["u847398b275fbc83c492eb7a21f26bd94"],"toChannel":1461808908}]}
The linebot
package currently pulls in 3rd party context
and ctxhttp
as its only dependencies.
Those are part of the standard library as of Go 1.7. Almost all packages follow the pattern of supporting current and last releases of Go, so this is currently supporting many more versions than any of my other dependencies.
Are there any plans of moving to standard library context with this SDK? Considering the situation around Go and dependency management I guess it's a good idea to have a dependency less package for others to depend on if possible.
Yep I read that I can't use SDK on localhost... but how is possible to develop something without testing? Develop on a production server?
I really don't understand...
Whats the best practice to do a good bot without it?
Thanks!
CodeCov is SaaS to visualize code coverage, and useful to improve code quality.
Note that the below samples refer my personal repositories.
https://developers.line.me/en/news/tags/messaging-api/
"destination" field in the webhook.
https://developers.line.biz/en/reference/messaging-api/#webhooks
New fields in Image, Video, and Audio.
Please add fields for beans and implement sample in the kitchensink.
Add method for POST https://api.line.me/v2/bot/user/{userId}/linkToken
https://developers.line.biz/en/reference/messaging-api/#issue-link-token
i used the message api basic plan's pushmessage feature for some months.
but recently get the error as the title said frequency.
please tell me how to resolve it?
Currently, response handler seems to be redundancy to handle events like below.
http.HandleFunc("/callback", func(w http.ResponseWriter, req *http.Request) {
events, err := bot.ParseRequest(req)
if err != nil {
if err == linebot.ErrInvalidSignature {
w.WriteHeader(400)
} else {
w.WriteHeader(500)
}
return
}
// code here
}
So I suggest to add new method client.HandleFunc
like below.
diff --git a/linebot/receive.go b/linebot/receive.go
index 5354c8f..92068cb 100644
--- a/linebot/receive.go
+++ b/linebot/receive.go
@@ -279,6 +279,21 @@ func (client *Client) ParseRequest(r *http.Request) (events *ReceivedResults, e
return
}
+func (client *Client) HandleFunc(handler func(requests *ReceivedResults)) http.HandlerFunc {
+ return func(w http.ResponseWriter, req *http.Request) {
+ events, err := client.ParseRequest(req)
+ if err != nil {
+ if err == ErrInvalidSignature {
+ w.WriteHeader(400)
+ } else {
+ w.WriteHeader(500)
+ }
+ return
+ }
+ handler(events)
+ }
+}
+
func (client *Client) validateSignature(signature string, body []byte) bool {
decoded, err := base64.StdEncoding.DecodeString(signature)
if err != nil {
Using this method, this part will be shorter.
func main() {
bot, err := linebot.New(
os.Getenv("CHANNEL_SECRET"),
os.Getenv("CHANNEL_TOKEN"),
)
if err != nil {
log.Fatal(err)
}
// Setup HTTP Server for receiving requests from LINE platform
http.HandleFunc("/callback", bot.HandleFunc(events *linebot.ReceivedResults) {
for _, event := range events {
if event.Type == linebot.EventTypeMessage {
switch message := event.Message.(type) {
case *linebot.TextMessage:
source := event.Source
if source.Type == linebot.EventSourceTypeUser {
if _, err = bot.PushMessage(source.UserID, linebot.NewTextMessage(message.Text)).Do(); err != nil {
log.Print(err)
}
}
}
}
}
})
if err := http.ListenAndServe(":"+os.Getenv("PORT"), nil); err != nil {
log.Fatal(err)
}
}
https://developers.line.me/en/docs/messaging-api/reference/#action-objects
I found the property "Label" in action objects is able to be optional for image carousel template.
The template action should be converted to JSON with omitempty
tag.
check #74
Let's keep the quality of the code.
Can you provides the API to allow callback URL to be set?
Please support urlfetch.
FYI: https://godoc.org/google.golang.org/appengine/urlfetch
Like this
var bot *linebot.Client
func init() {
bot = linebot.New(
os.Getenv("LINE_BOT_CHANNEL_SECRET"),
os.Getenv("LINE_BOT_CHANNEL_TOKEN"))
}
func handle(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
...
if _, err = bot.PushMessage(...).Context(ctx).Do(); err != nil {
log.Errorf(ctx, "Push Message error: %v", err)
}
}
Hello, I read "https://devdocs.line.me/en/#send-message-object" and "https://devdocs.line.me/ja/#send-message-object"
Text of Send Message Object
Type = String
Content = メッセージのテキスト 2000 文字以内
If my string is test_string
.
test_string := "あaいbうcえdお"
fmt.Println(len(test_string)) // print 19 https://play.golang.org/p/gaj9bbhwGL
The test_string
string var characters
is 19 or 9?
In Japanese API Reference is 2000 文字
以内, but In English API Reference use 2000 characters
.
My question is whether he is based on "Golang len ()" to determine the max characters? or not?
If "日本語" = 3? or =9? (https://play.golang.org/p/HtFde0Tbs9)
Suppose today API set Max: 3 characters
test_string:= "日本語"
is OK to sent?
Or because len("日本語") == 9
, go to error?
I have a string is Japanese and words over 2000.
I find this way (http://ashitani.jp/golangtips/tips_string.html#string_Extract) to split display.
test_string[0:2000]
But the way is use byte? words will lose. Less than 2000 words.
And I try test_string[0:6000]
, get error "linebot: APIError 400 The request body has 1 error(s)\n[messages[0].text] Length must be between 0 and 2000"
again.
I solved.
I found that the problem is UTF-8.
I refer to the following three sites:
Https://blog.golang.org/strings
Http://stackoverflow.com/questions/15018545/how-to-index-characters-in-a-golang-string
Https://golang.org/ref/spec#Conversions
Finally, in this way solution
Https://play.golang.org/p/S96z8w1xcb
// Used to LINE API send-message
Fmt.Println ("ONE LINE")
Fmt.Println (string ([] rune (test_string) [0: 2000]))
Fmt.Println ("TWO LINE")
Fmt.Println (string ([] rune (test_string) [2000: len ([] rune (test_string))]))
This will solve the long message.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.