Skip to content

Commit 7bb6882

Browse files
authored
Openapi (#365)
1 parent bdd2a67 commit 7bb6882

File tree

388 files changed

+28720
-526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

388 files changed

+28720
-526
lines changed

.github/workflows/go.yml

+23
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,40 @@ jobs:
2020
- '1.20.6'
2121
steps:
2222
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
23+
with:
24+
submodules: true
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v4
28+
with:
29+
python-version: '3.x'
2330

2431
- name: Set up Go
2532
uses: actions/setup-go@v4
2633
with:
2734
go-version: ${{ matrix.go }}
2835

36+
- name: Install goimports
37+
run: go install golang.org/x/tools/cmd/goimports@latest
38+
39+
40+
- name: Generate code
41+
run: python generate-code.py
42+
2943
- name: run codecov.sh
3044
run: bash script/codecov.sh
3145

3246
- name: go vet
3347
run: go vet $(go list ./... | grep -v /examples/)
3448

49+
- name: Compile example scripts
50+
run: |
51+
for file in $(find ./examples/ -name '*.go'); do
52+
dir=$(dirname $file)
53+
pushd $dir
54+
go build -o /dev/null
55+
popd
56+
done
57+
3558
- name: Publish to codecov.io
3659
run: bash <(curl -s https://codecov.io/bash)

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ _testmain.go
2424
*.prof
2525

2626
.idea*
27+
28+
/.vscode/

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "line-openapi"]
2+
path = line-openapi
3+
url = [email protected]:line/line-openapi.git

README.md

+66-42
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,57 @@ $ go get -u github.com/line/line-bot-sdk-go/v7/linebot
3030

3131
```go
3232
import (
33-
"github.com/line/line-bot-sdk-go/v7/linebot"
33+
"github.com/line/line-bot-sdk-go/v7/linebot/messaging_api"
3434
)
3535

3636
func main() {
37-
bot, err := linebot.New("<channel secret>", "<channel access token>")
37+
bot, err := messaging_api.NewMessagingApiAPI(
38+
os.Getenv("LINE_CHANNEL_TOKEN"),
39+
)
3840
...
3941
}
4042

4143
```
4244

4345
### Configuration with http.Client ###
4446

47+
Every client application allows configuration with WithHTTPClient and WithEndpoint.
48+
(For Blob client, configurations WithBlobHTTPClient and WithBlobEndpoint are also available.)
49+
4550
```go
4651
client := &http.Client{}
47-
bot, err := linebot.New("<channel secret>", "<channel access token>", linebot.WithHTTPClient(client))
52+
bot, err := messaging_api.NewMessagingApiAPI(
53+
os.Getenv("LINE_CHANNEL_TOKEN"),
54+
messaging_api.WithHTTPClient(client),
55+
)
4856
...
4957
```
5058

51-
## How to start ##
59+
## Getting Started ##
5260

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.
61+
The LINE Messaging API primarily utilizes the JSON data format. To parse the incoming HTTP requests, the `webhook.ParseRequest()` method is provided. This method reads the `*http.Request` content and returns a slice of pointers to Event Objects.
5562

5663
```go
57-
events, err := bot.ParseRequest(req)
64+
import (
65+
"github.com/line/line-bot-sdk-go/v7/linebot/webhook"
66+
)
67+
68+
cb, err := webhook.ParseRequest(req)
5869
if err != nil {
59-
// Do something when something bad happened.
70+
// Handle any errors that occur.
6071
}
6172
```
6273

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```
74+
The LINE Messaging API is capable of handling various event types. The Messaging API SDK automatically unmarshals these events into respective classes like `webhook.MessageEvent`, `webhook.FollowEvent`, and so on. You can easily check the type of the event and respond accordingly using a switch statement as shown below:
75+
6476

6577
```go
66-
for _, event := range events {
67-
if event.Type == linebot.EventTypeMessage {
68-
// Do Something...
78+
for _, event := range cb.Events {
79+
switch e := event.(type) {
80+
case webhook.MessageEvent:
81+
// Do Something...
82+
case webhook.StickerMessageContent:
83+
// Do Something...
6984
}
7085
}
7186
```
@@ -75,9 +90,9 @@ for _, event := range events {
7590
To send a message to a user, group, or room, you need either an ID
7691

7792
```go
78-
userID := event.Source.UserID
79-
groupID := event.Source.GroupID
80-
RoomID := event.Source.RoomID
93+
userID := event.Source.UserId
94+
groupID := event.Source.GroupId
95+
RoomID := event.Source.RoomId
8196
```
8297

8398
or a reply token.
@@ -88,43 +103,52 @@ replyToken := event.ReplyToken
88103

89104
### Create message ###
90105

91-
The LINE Messaging API provides various types of message. To create a message, use ```New<Type>Message()```.
106+
The LINE Messaging API provides various types of message.
92107

93108
```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)
109+
bot.ReplyMessage(
110+
&messaging_api.ReplyMessageRequest{
111+
ReplyToken: e.ReplyToken,
112+
Messages: []messaging_api.MessageInterface{
113+
messaging_api.TextMessage{
114+
Text: replyMessage,
115+
},
116+
},
117+
},
118+
)
100119
```
101120

102121
### Send message ###
103122

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

106125
```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-
}
126+
bot.PushMessage(
127+
&messaging_api.PushMessageRequest{
128+
To: "U.......",
129+
Messages: []messaging_api.MessageInterface{
130+
messaging_api.TextMessage{
131+
Text: replyMessage,
132+
},
133+
},
134+
},
135+
nil, // x-line-retry-key
136+
)
115137
```
116138

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

119141
```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-
}
142+
bot.ReplyMessage(
143+
&messaging_api.ReplyMessageRequest{
144+
ReplyToken: e.ReplyToken,
145+
Messages: []messaging_api.MessageInterface{
146+
messaging_api.TextMessage{
147+
Text: replyMessage,
148+
},
149+
},
150+
},
151+
)
128152
```
129153

130154
## Help and media
@@ -135,7 +159,7 @@ Community Q&A: https://www.line-community.me/questions
135159

136160
News: https://developers.line.biz/en/news/
137161

138-
Twitter: @LINE_DEV
162+
X: @LINE_DEV
139163

140164

141165
## Versioning
@@ -153,13 +177,13 @@ Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution.
153177

154178
```
155179
Copyright (C) 2016 LINE Corp.
156-
180+
157181
Licensed under the Apache License, Version 2.0 (the "License");
158182
you may not use this file except in compliance with the License.
159183
You may obtain a copy of the License at
160-
184+
161185
http://www.apache.org/licenses/LICENSE-2.0
162-
186+
163187
Unless required by applicable law or agreed to in writing, software
164188
distributed under the License is distributed on an "AS IS" BASIS,
165189
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

examples/access_token_helper/main.go

-60
This file was deleted.

examples/delivery_helper/main.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"log"
2020
"os"
2121

22-
"github.com/line/line-bot-sdk-go/v7/linebot"
22+
"github.com/line/line-bot-sdk-go/v7/linebot/messaging_api"
2323
)
2424

2525
func main() {
@@ -28,24 +28,25 @@ func main() {
2828
date = flag.String("date", "", "date the messages were sent, format 'yyyyMMdd'")
2929
)
3030
flag.Parse()
31-
bot, err := linebot.New(
32-
os.Getenv("CHANNEL_SECRET"),
33-
os.Getenv("CHANNEL_TOKEN"),
31+
client, err := messaging_api.NewMessagingApiAPI(
32+
os.Getenv("LINE_CHANNEL_TOKEN"),
3433
)
3534
if err != nil {
3635
log.Fatal(err)
3736
}
3837

39-
var res *linebot.MessagesNumberResponse
38+
log.Printf("Getting stats for date=%s, mode=%s\n", *date, *mode)
39+
40+
var res *messaging_api.NumberOfMessagesResponse
4041
switch *mode {
4142
case "multicast":
42-
res, err = bot.GetNumberMulticastMessages(*date).Do()
43+
res, err = client.GetNumberOfSentMulticastMessages(*date)
4344
case "push":
44-
res, err = bot.GetNumberPushMessages(*date).Do()
45+
res, err = client.GetNumberOfSentPushMessages(*date)
4546
case "reply":
46-
res, err = bot.GetNumberReplyMessages(*date).Do()
47+
res, err = client.GetNumberOfSentReplyMessages(*date)
4748
case "broadcast":
48-
res, err = bot.GetNumberBroadcastMessages(*date).Do()
49+
res, err = client.GetNumberOfSentBroadcastMessages(*date)
4950
default:
5051
log.Fatal("implement me")
5152
}

0 commit comments

Comments
 (0)