line-bot-sdk-rs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +183 -0
- package/index.d.ts +327 -0
- package/index.js +591 -0
- package/package.json +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 N-API for Rust
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# line-bot-sdk
|
|
2
|
+
|
|
3
|
+
High-performance [LINE Messaging API](https://developers.line.biz/en/reference/messaging-api/) SDK for **Node.js / TypeScript**, powered by **Rust** native bindings via [napi-rs](https://napi.rs).
|
|
4
|
+
|
|
5
|
+
> **Disclaimer:** This is a community SDK and is **not** affiliated with or endorsed by LINE Corporation. For the official SDK, see [@line/bot-sdk](https://www.npmjs.com/package/@line/bot-sdk).
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Native performance** — core HTTP client and crypto run in Rust
|
|
10
|
+
- **Full TypeScript support** — auto-generated types + ergonomic wrapper
|
|
11
|
+
- **Messaging** — push, reply, multicast, broadcast, quota, content download
|
|
12
|
+
- **Profile & followers** — user profile, follower IDs
|
|
13
|
+
- **Group & room** — member profiles, member IDs, leave group/room
|
|
14
|
+
- **Rich menu** — create, upload image, link/unlink, bulk operations
|
|
15
|
+
- **Insight** — message delivery overview, followers statistics
|
|
16
|
+
- **Webhook** — signature verification and typed event parsing
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- Node.js `>= 18.17.0` (or 20+, 21+)
|
|
21
|
+
- [Rust](https://rustup.rs/) (for building from source)
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @panudetingai/line-bot-sdk
|
|
27
|
+
# or
|
|
28
|
+
yarn add @panudetingai/line-bot-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### 1. Create a client
|
|
34
|
+
|
|
35
|
+
Get your **Channel Access Token** from [LINE Developers Console](https://developers.line.biz/console/).
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { LineClient } from '@panudetingai/line-bot-sdk'
|
|
39
|
+
|
|
40
|
+
const client = new LineClient(process.env.LINE_CHANNEL_ACCESS_TOKEN!)
|
|
41
|
+
|
|
42
|
+
const bot = await client.getBotInfo()
|
|
43
|
+
console.log(bot.displayName)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Send messages
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
await client.pushText('Uxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Hello from line-bot-sdk!')
|
|
50
|
+
|
|
51
|
+
await client.pushMessages('Uxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [
|
|
52
|
+
{ type: 'text', text: 'Hello!' },
|
|
53
|
+
{ type: 'sticker', packageId: '446', stickerId: '1988' },
|
|
54
|
+
])
|
|
55
|
+
|
|
56
|
+
await client.replyText(replyToken, 'Got your message!')
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 3. Get user profile
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const profile = await client.getProfile('Uxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|
|
63
|
+
console.log(profile.displayName, profile.pictureUrl)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 4. Webhook handler (Next.js / Express)
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { verifySignature, parseWebhook, LineClient } from '@panudetingai/line-bot-sdk'
|
|
70
|
+
|
|
71
|
+
const CHANNEL_SECRET = process.env.LINE_CHANNEL_SECRET!
|
|
72
|
+
const client = new LineClient(process.env.LINE_CHANNEL_ACCESS_TOKEN!)
|
|
73
|
+
|
|
74
|
+
export async function POST(req: Request) {
|
|
75
|
+
const rawBody = await req.text()
|
|
76
|
+
const signature = req.headers.get('x-line-signature') ?? ''
|
|
77
|
+
|
|
78
|
+
if (!verifySignature(rawBody, signature, CHANNEL_SECRET)) {
|
|
79
|
+
return new Response('Invalid signature', { status: 401 })
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { events } = parseWebhook(rawBody)
|
|
83
|
+
|
|
84
|
+
for (const event of events) {
|
|
85
|
+
if (event.type === 'message' && event.message?.type === 'text') {
|
|
86
|
+
await client.replyText(event.replyToken!, `You said: ${event.message.text}`)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return new Response('OK')
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## API Overview
|
|
95
|
+
|
|
96
|
+
### `LineClient`
|
|
97
|
+
|
|
98
|
+
| Category | Methods |
|
|
99
|
+
|----------|---------|
|
|
100
|
+
| **Bot** | `getBotInfo()` |
|
|
101
|
+
| **Messaging** | `pushText`, `pushMessages`, `replyText`, `replyMessages`, `multicast`, `broadcast` |
|
|
102
|
+
| **Quota** | `getMessageQuota()`, `getMessageQuotaConsumption()` |
|
|
103
|
+
| **Content** | `getMessageContent(messageId)` |
|
|
104
|
+
| **Profile** | `getProfile(userId)`, `getFollowerIds(next?)` |
|
|
105
|
+
| **Group** | `getGroupSummary`, `getGroupMemberProfile`, `getGroupMemberIds`, `leaveGroup` |
|
|
106
|
+
| **Room** | `getRoomMemberProfile`, `getRoomMemberIds`, `leaveRoom` |
|
|
107
|
+
| **Rich Menu** | `createRichMenu`, `uploadRichMenuImage`, `setDefaultRichMenu`, `linkRichMenuToUser`, ... |
|
|
108
|
+
| **Insight** | `getMessageDeliveryOverview(date)`, `getFollowersInsight(date)` |
|
|
109
|
+
|
|
110
|
+
### Webhook helpers
|
|
111
|
+
|
|
112
|
+
| Function | Description |
|
|
113
|
+
|----------|-------------|
|
|
114
|
+
| `verifySignature(body, signature, channelSecret)` | Validate `X-Line-Signature` header |
|
|
115
|
+
| `parseWebhook(body)` | Parse webhook JSON into typed `WebhookBody` |
|
|
116
|
+
|
|
117
|
+
## Environment Variables
|
|
118
|
+
|
|
119
|
+
| Variable | Description |
|
|
120
|
+
|----------|-------------|
|
|
121
|
+
| `LINE_CHANNEL_ACCESS_TOKEN` | Channel access token for API calls |
|
|
122
|
+
| `LINE_CHANNEL_SECRET` | Channel secret for webhook signature verification |
|
|
123
|
+
|
|
124
|
+
Never commit tokens to git. Use `.env` locally and secrets in CI/production.
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
yarn install
|
|
130
|
+
yarn build:debug
|
|
131
|
+
yarn test
|
|
132
|
+
|
|
133
|
+
# Integration test with a real token
|
|
134
|
+
LINE_CHANNEL_ACCESS_TOKEN=xxx yarn test
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Project structure
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
src/
|
|
141
|
+
├── client.rs # HTTP client & auth
|
|
142
|
+
├── api/endpoints.rs # LINE API URL paths
|
|
143
|
+
├── services/ # API methods (messaging, profile, group, ...)
|
|
144
|
+
├── types/ # Request/response types
|
|
145
|
+
└── webhook.rs # Signature verify & event parsing
|
|
146
|
+
|
|
147
|
+
typescript/
|
|
148
|
+
├── line-client.ts # Ergonomic TypeScript wrapper
|
|
149
|
+
└── types.ts # Shared TypeScript types
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Low-level API
|
|
153
|
+
|
|
154
|
+
Call the native binding directly if you prefer:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { LineClient } from './index'
|
|
158
|
+
|
|
159
|
+
const client = new LineClient(token)
|
|
160
|
+
await client.pushMessage('Uxxx', 'hello')
|
|
161
|
+
await client.getProfile('Uxxx')
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The TypeScript wrapper in `typescript/line-client.ts` provides a cleaner API (objects instead of JSON strings).
|
|
165
|
+
|
|
166
|
+
## Platform Support
|
|
167
|
+
|
|
168
|
+
Prebuilt binaries for:
|
|
169
|
+
|
|
170
|
+
- macOS (x64, arm64)
|
|
171
|
+
- Linux (x64 gnu)
|
|
172
|
+
- Windows (x64)
|
|
173
|
+
|
|
174
|
+
Built with [napi-rs](https://napi.rs) — no `node-gyp` or C++ toolchain required for end users.
|
|
175
|
+
|
|
176
|
+
## Related Projects
|
|
177
|
+
|
|
178
|
+
- [@line/bot-sdk](https://github.com/line/line-bot-sdk-nodejs) — Official LINE Bot SDK for Node.js
|
|
179
|
+
- [line-bot-sdk-rust](https://crates.io/crates/line-bot-sdk-rust) — LINE SDK for pure Rust applications
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT © [Panudetingai](https://github.com/Panudetingai)
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class LineClient {
|
|
4
|
+
constructor(accessToken: string)
|
|
5
|
+
verify(): Promise<BotInfo>
|
|
6
|
+
getGroupSummary(groupId: string): Promise<GroupSummary>
|
|
7
|
+
getGroupMemberProfile(groupId: string, userId: string): Promise<GroupMemberProfile>
|
|
8
|
+
getGroupMemberIds(groupId: string, next?: string | undefined | null): Promise<MemberIds>
|
|
9
|
+
leaveGroup(groupId: string): Promise<string>
|
|
10
|
+
getRoomMemberProfile(roomId: string, userId: string): Promise<GroupMemberProfile>
|
|
11
|
+
getRoomMemberIds(roomId: string, next?: string | undefined | null): Promise<MemberIds>
|
|
12
|
+
leaveRoom(roomId: string): Promise<string>
|
|
13
|
+
/** `date` format: YYYYMMDD (e.g. "20240101") */
|
|
14
|
+
getMessageDeliveryOverview(date: string): Promise<MessageDeliveryOverview>
|
|
15
|
+
/** `date` format: YYYYMMDD */
|
|
16
|
+
getFollowersInsight(date: string): Promise<FollowersInsight>
|
|
17
|
+
pushMessage(to: string, text: string): Promise<string>
|
|
18
|
+
replyMessage(replyToken: string, text: string): Promise<string>
|
|
19
|
+
/**
|
|
20
|
+
* Send any message types. `messages_json` = JSON array string.
|
|
21
|
+
* e.g. '[{"type":"text","text":"Hi"},{"type":"image",...}]'
|
|
22
|
+
*/
|
|
23
|
+
pushMessages(to: string, messagesJson: string): Promise<string>
|
|
24
|
+
/** Reply with any message types. `messages_json` = JSON array string. */
|
|
25
|
+
replyMessages(replyToken: string, messagesJson: string): Promise<string>
|
|
26
|
+
/** Multicast to multiple users. `user_ids_json` = JSON string array. */
|
|
27
|
+
multicast(userIdsJson: string, messagesJson: string): Promise<string>
|
|
28
|
+
/** Broadcast to all followers. `messages_json` = JSON array string. */
|
|
29
|
+
broadcast(messagesJson: string): Promise<string>
|
|
30
|
+
getMessageQuota(): Promise<MessageQuota>
|
|
31
|
+
getMessageQuotaConsumption(): Promise<MessageQuotaConsumption>
|
|
32
|
+
getMessageContent(messageId: string): Promise<Buffer>
|
|
33
|
+
getProfile(userId: string): Promise<Profile>
|
|
34
|
+
/** Returns follower user IDs. Pass `next` cursor for pagination (empty string for first page). */
|
|
35
|
+
getFollowerIds(next?: string | undefined | null): Promise<FollowerIds>
|
|
36
|
+
createRichMenu(richMenu: RichMenu): Promise<string>
|
|
37
|
+
getRichMenu(richMenuId: string): Promise<RichMenuResponse>
|
|
38
|
+
deleteRichMenu(richMenuId: string): Promise<string>
|
|
39
|
+
getRichMenuList(): Promise<RichMenuList>
|
|
40
|
+
/** Upload rich menu image. `content_type` is e.g. "image/jpeg" or "image/png". */
|
|
41
|
+
uploadRichMenuImage(richMenuId: string, imageData: Buffer, contentType: string): Promise<string>
|
|
42
|
+
/** Download rich menu image. Returns raw bytes as Buffer. */
|
|
43
|
+
downloadRichMenuImage(richMenuId: string): Promise<Buffer>
|
|
44
|
+
setDefaultRichMenu(richMenuId: string): Promise<string>
|
|
45
|
+
cancelDefaultRichMenu(): Promise<string>
|
|
46
|
+
getUserRichMenu(userId: string): Promise<RichMenuIdResponse>
|
|
47
|
+
linkRichMenuToUser(userId: string, richMenuId: string): Promise<string>
|
|
48
|
+
unlinkRichMenuFromUser(userId: string): Promise<string>
|
|
49
|
+
/** Bulk link rich menu to multiple users. `user_ids_json` = JSON array string. */
|
|
50
|
+
bulkLinkRichMenu(richMenuId: string, userIdsJson: string): Promise<string>
|
|
51
|
+
/** Bulk unlink rich menu from multiple users. `user_ids_json` = JSON array string. */
|
|
52
|
+
bulkUnlinkRichMenu(userIdsJson: string): Promise<string>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface AudioMessage {
|
|
56
|
+
messageType: string
|
|
57
|
+
originalContentUrl: string
|
|
58
|
+
duration: number
|
|
59
|
+
quickReply?: QuickReply
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface BeaconContent {
|
|
63
|
+
hwid: string
|
|
64
|
+
beaconType: string
|
|
65
|
+
dm?: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface BotInfo {
|
|
69
|
+
userId: string
|
|
70
|
+
basicId: string
|
|
71
|
+
displayName: string
|
|
72
|
+
pictureUrl: string
|
|
73
|
+
chatMode: string
|
|
74
|
+
markAsReadMode: string
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ContentProvider {
|
|
78
|
+
providerType: string
|
|
79
|
+
originalContentUrl?: string
|
|
80
|
+
previewImageUrl?: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface DeliveryContext {
|
|
84
|
+
isRedelivery: boolean
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface EventMessage {
|
|
88
|
+
id: string
|
|
89
|
+
messageType: string
|
|
90
|
+
text?: string
|
|
91
|
+
contentProvider?: ContentProvider
|
|
92
|
+
duration?: number
|
|
93
|
+
fileName?: string
|
|
94
|
+
fileSize?: number
|
|
95
|
+
title?: string
|
|
96
|
+
address?: string
|
|
97
|
+
latitude?: number
|
|
98
|
+
longitude?: number
|
|
99
|
+
packageId?: string
|
|
100
|
+
stickerId?: string
|
|
101
|
+
stickerResourceType?: string
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface EventSource {
|
|
105
|
+
sourceType: string
|
|
106
|
+
userId?: string
|
|
107
|
+
groupId?: string
|
|
108
|
+
roomId?: string
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface FollowerIds {
|
|
112
|
+
userIds: Array<string>
|
|
113
|
+
next?: string
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface FollowersInsight {
|
|
117
|
+
status: string
|
|
118
|
+
followers?: number
|
|
119
|
+
targetedReaches?: number
|
|
120
|
+
blocks?: number
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface GroupMemberProfile {
|
|
124
|
+
displayName: string
|
|
125
|
+
userId: string
|
|
126
|
+
pictureUrl?: string
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface GroupSummary {
|
|
130
|
+
groupId: string
|
|
131
|
+
groupName: string
|
|
132
|
+
pictureUrl?: string
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface ImageMessage {
|
|
136
|
+
messageType: string
|
|
137
|
+
originalContentUrl: string
|
|
138
|
+
previewImageUrl: string
|
|
139
|
+
quickReply?: QuickReply
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface LinkContent {
|
|
143
|
+
result: string
|
|
144
|
+
nonce: string
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface LocationMessage {
|
|
148
|
+
messageType: string
|
|
149
|
+
title: string
|
|
150
|
+
address: string
|
|
151
|
+
latitude: number
|
|
152
|
+
longitude: number
|
|
153
|
+
quickReply?: QuickReply
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface MemberIds {
|
|
157
|
+
memberIds: Array<string>
|
|
158
|
+
next?: string
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface MessageDeliveryOverview {
|
|
162
|
+
status: string
|
|
163
|
+
broadcast?: number
|
|
164
|
+
targeting?: number
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface MessageQuota {
|
|
168
|
+
quotaType: string
|
|
169
|
+
value?: number
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface MessageQuotaConsumption {
|
|
173
|
+
totalUsage: number
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Parse a webhook body JSON string into typed events.
|
|
178
|
+
* Throws if the JSON is invalid.
|
|
179
|
+
*/
|
|
180
|
+
export declare function parseWebhookBody(body: string): WebhookBody
|
|
181
|
+
|
|
182
|
+
export interface PostbackContent {
|
|
183
|
+
data: string
|
|
184
|
+
params?: PostbackParams
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface PostbackParams {
|
|
188
|
+
date?: string
|
|
189
|
+
time?: string
|
|
190
|
+
datetime?: string
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface Profile {
|
|
194
|
+
displayName: string
|
|
195
|
+
userId: string
|
|
196
|
+
pictureUrl?: string
|
|
197
|
+
statusMessage?: string
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface PushMessageRequest {
|
|
201
|
+
to: string
|
|
202
|
+
messages: Array<TextMessage>
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface QuickReply {
|
|
206
|
+
items: Array<QuickReplyItem>
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface QuickReplyAction {
|
|
210
|
+
actionType: string
|
|
211
|
+
label: string
|
|
212
|
+
text?: string
|
|
213
|
+
data?: string
|
|
214
|
+
uri?: string
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface QuickReplyItem {
|
|
218
|
+
itemType: string
|
|
219
|
+
action: QuickReplyAction
|
|
220
|
+
imageUrl?: string
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface ReplyMessageRequest {
|
|
224
|
+
replyToken: string
|
|
225
|
+
messages: Array<TextMessage>
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface RichMenu {
|
|
229
|
+
size: RichMenuSize
|
|
230
|
+
selected: boolean
|
|
231
|
+
name: string
|
|
232
|
+
chatBarText: string
|
|
233
|
+
areas: Array<RichMenuArea>
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface RichMenuAction {
|
|
237
|
+
actionType: string
|
|
238
|
+
label?: string
|
|
239
|
+
text?: string
|
|
240
|
+
uri?: string
|
|
241
|
+
data?: string
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface RichMenuArea {
|
|
245
|
+
bounds: RichMenuBounds
|
|
246
|
+
action: RichMenuAction
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface RichMenuBounds {
|
|
250
|
+
x: number
|
|
251
|
+
y: number
|
|
252
|
+
width: number
|
|
253
|
+
height: number
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface RichMenuIdResponse {
|
|
257
|
+
richMenuId: string
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface RichMenuList {
|
|
261
|
+
richmenus: Array<RichMenuResponse>
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface RichMenuResponse {
|
|
265
|
+
richMenuId: string
|
|
266
|
+
size: RichMenuSize
|
|
267
|
+
selected: boolean
|
|
268
|
+
name: string
|
|
269
|
+
chatBarText: string
|
|
270
|
+
areas: Array<RichMenuArea>
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface RichMenuSize {
|
|
274
|
+
width: number
|
|
275
|
+
height: number
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface Sender {
|
|
279
|
+
name?: string
|
|
280
|
+
iconUrl?: string
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface StickerMessage {
|
|
284
|
+
messageType: string
|
|
285
|
+
packageId: string
|
|
286
|
+
stickerId: string
|
|
287
|
+
quickReply?: QuickReply
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface TextMessage {
|
|
291
|
+
messageType: string
|
|
292
|
+
text: string
|
|
293
|
+
quickReply?: QuickReply
|
|
294
|
+
sender?: Sender
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Verify the X-Line-Signature header against the raw request body.
|
|
299
|
+
* Returns true if the signature is valid.
|
|
300
|
+
*/
|
|
301
|
+
export declare function verifyWebhookSignature(body: string, signature: string, channelSecret: string): boolean
|
|
302
|
+
|
|
303
|
+
export interface VideoMessage {
|
|
304
|
+
messageType: string
|
|
305
|
+
originalContentUrl: string
|
|
306
|
+
previewImageUrl: string
|
|
307
|
+
trackingId?: string
|
|
308
|
+
quickReply?: QuickReply
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export interface WebhookBody {
|
|
312
|
+
destination: string
|
|
313
|
+
events: Array<WebhookEvent>
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface WebhookEvent {
|
|
317
|
+
eventType: string
|
|
318
|
+
timestamp: number
|
|
319
|
+
source: EventSource
|
|
320
|
+
webhookEventId?: string
|
|
321
|
+
deliveryContext?: DeliveryContext
|
|
322
|
+
replyToken?: string
|
|
323
|
+
message?: EventMessage
|
|
324
|
+
postback?: PostbackContent
|
|
325
|
+
beacon?: BeaconContent
|
|
326
|
+
link?: LinkContent
|
|
327
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const { readFileSync } = require('node:fs')
|
|
7
|
+
let nativeBinding = null
|
|
8
|
+
const loadErrors = []
|
|
9
|
+
|
|
10
|
+
const isMusl = () => {
|
|
11
|
+
let musl = false
|
|
12
|
+
if (process.platform === 'linux') {
|
|
13
|
+
musl = isMuslFromFilesystem()
|
|
14
|
+
if (musl === null) {
|
|
15
|
+
musl = isMuslFromReport()
|
|
16
|
+
}
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromChildProcess()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return musl
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
25
|
+
|
|
26
|
+
const isMuslFromFilesystem = () => {
|
|
27
|
+
try {
|
|
28
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
29
|
+
} catch {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isMuslFromReport = () => {
|
|
35
|
+
let report = null
|
|
36
|
+
if (typeof process.report?.getReport === 'function') {
|
|
37
|
+
process.report.excludeNetwork = true
|
|
38
|
+
report = process.report.getReport()
|
|
39
|
+
}
|
|
40
|
+
if (!report) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
47
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isMuslFromChildProcess = () => {
|
|
55
|
+
try {
|
|
56
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
57
|
+
} catch (e) {
|
|
58
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function requireNative() {
|
|
64
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
65
|
+
try {
|
|
66
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
loadErrors.push(err)
|
|
69
|
+
}
|
|
70
|
+
} else if (process.platform === 'android') {
|
|
71
|
+
if (process.arch === 'arm64') {
|
|
72
|
+
try {
|
|
73
|
+
return require('./line-bot-sdk-rs.android-arm64.node')
|
|
74
|
+
} catch (e) {
|
|
75
|
+
loadErrors.push(e)
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const binding = require('line-bot-sdk-rs-android-arm64')
|
|
79
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-android-arm64/package.json').version
|
|
80
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
|
+
}
|
|
83
|
+
return binding
|
|
84
|
+
} catch (e) {
|
|
85
|
+
loadErrors.push(e)
|
|
86
|
+
}
|
|
87
|
+
} else if (process.arch === 'arm') {
|
|
88
|
+
try {
|
|
89
|
+
return require('./line-bot-sdk-rs.android-arm-eabi.node')
|
|
90
|
+
} catch (e) {
|
|
91
|
+
loadErrors.push(e)
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const binding = require('line-bot-sdk-rs-android-arm-eabi')
|
|
95
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-android-arm-eabi/package.json').version
|
|
96
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
|
+
}
|
|
99
|
+
return binding
|
|
100
|
+
} catch (e) {
|
|
101
|
+
loadErrors.push(e)
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
105
|
+
}
|
|
106
|
+
} else if (process.platform === 'win32') {
|
|
107
|
+
if (process.arch === 'x64') {
|
|
108
|
+
if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
|
|
109
|
+
try {
|
|
110
|
+
return require('./line-bot-sdk-rs.win32-x64-gnu.node')
|
|
111
|
+
} catch (e) {
|
|
112
|
+
loadErrors.push(e)
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const binding = require('line-bot-sdk-rs-win32-x64-gnu')
|
|
116
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-win32-x64-gnu/package.json').version
|
|
117
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
|
+
}
|
|
120
|
+
return binding
|
|
121
|
+
} catch (e) {
|
|
122
|
+
loadErrors.push(e)
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
try {
|
|
126
|
+
return require('./line-bot-sdk-rs.win32-x64-msvc.node')
|
|
127
|
+
} catch (e) {
|
|
128
|
+
loadErrors.push(e)
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const binding = require('line-bot-sdk-rs-win32-x64-msvc')
|
|
132
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-win32-x64-msvc/package.json').version
|
|
133
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
|
+
}
|
|
136
|
+
return binding
|
|
137
|
+
} catch (e) {
|
|
138
|
+
loadErrors.push(e)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else if (process.arch === 'ia32') {
|
|
142
|
+
try {
|
|
143
|
+
return require('./line-bot-sdk-rs.win32-ia32-msvc.node')
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadErrors.push(e)
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const binding = require('line-bot-sdk-rs-win32-ia32-msvc')
|
|
149
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-win32-ia32-msvc/package.json').version
|
|
150
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
|
+
}
|
|
153
|
+
return binding
|
|
154
|
+
} catch (e) {
|
|
155
|
+
loadErrors.push(e)
|
|
156
|
+
}
|
|
157
|
+
} else if (process.arch === 'arm64') {
|
|
158
|
+
try {
|
|
159
|
+
return require('./line-bot-sdk-rs.win32-arm64-msvc.node')
|
|
160
|
+
} catch (e) {
|
|
161
|
+
loadErrors.push(e)
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const binding = require('line-bot-sdk-rs-win32-arm64-msvc')
|
|
165
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-win32-arm64-msvc/package.json').version
|
|
166
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
|
+
}
|
|
169
|
+
return binding
|
|
170
|
+
} catch (e) {
|
|
171
|
+
loadErrors.push(e)
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
175
|
+
}
|
|
176
|
+
} else if (process.platform === 'darwin') {
|
|
177
|
+
try {
|
|
178
|
+
return require('./line-bot-sdk-rs.darwin-universal.node')
|
|
179
|
+
} catch (e) {
|
|
180
|
+
loadErrors.push(e)
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const binding = require('line-bot-sdk-rs-darwin-universal')
|
|
184
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-darwin-universal/package.json').version
|
|
185
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
|
+
}
|
|
188
|
+
return binding
|
|
189
|
+
} catch (e) {
|
|
190
|
+
loadErrors.push(e)
|
|
191
|
+
}
|
|
192
|
+
if (process.arch === 'x64') {
|
|
193
|
+
try {
|
|
194
|
+
return require('./line-bot-sdk-rs.darwin-x64.node')
|
|
195
|
+
} catch (e) {
|
|
196
|
+
loadErrors.push(e)
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const binding = require('line-bot-sdk-rs-darwin-x64')
|
|
200
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-darwin-x64/package.json').version
|
|
201
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
|
+
}
|
|
204
|
+
return binding
|
|
205
|
+
} catch (e) {
|
|
206
|
+
loadErrors.push(e)
|
|
207
|
+
}
|
|
208
|
+
} else if (process.arch === 'arm64') {
|
|
209
|
+
try {
|
|
210
|
+
return require('./line-bot-sdk-rs.darwin-arm64.node')
|
|
211
|
+
} catch (e) {
|
|
212
|
+
loadErrors.push(e)
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const binding = require('line-bot-sdk-rs-darwin-arm64')
|
|
216
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-darwin-arm64/package.json').version
|
|
217
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
|
+
}
|
|
220
|
+
return binding
|
|
221
|
+
} catch (e) {
|
|
222
|
+
loadErrors.push(e)
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
226
|
+
}
|
|
227
|
+
} else if (process.platform === 'freebsd') {
|
|
228
|
+
if (process.arch === 'x64') {
|
|
229
|
+
try {
|
|
230
|
+
return require('./line-bot-sdk-rs.freebsd-x64.node')
|
|
231
|
+
} catch (e) {
|
|
232
|
+
loadErrors.push(e)
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const binding = require('line-bot-sdk-rs-freebsd-x64')
|
|
236
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-freebsd-x64/package.json').version
|
|
237
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
|
+
}
|
|
240
|
+
return binding
|
|
241
|
+
} catch (e) {
|
|
242
|
+
loadErrors.push(e)
|
|
243
|
+
}
|
|
244
|
+
} else if (process.arch === 'arm64') {
|
|
245
|
+
try {
|
|
246
|
+
return require('./line-bot-sdk-rs.freebsd-arm64.node')
|
|
247
|
+
} catch (e) {
|
|
248
|
+
loadErrors.push(e)
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
const binding = require('line-bot-sdk-rs-freebsd-arm64')
|
|
252
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-freebsd-arm64/package.json').version
|
|
253
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
|
+
}
|
|
256
|
+
return binding
|
|
257
|
+
} catch (e) {
|
|
258
|
+
loadErrors.push(e)
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
262
|
+
}
|
|
263
|
+
} else if (process.platform === 'linux') {
|
|
264
|
+
if (process.arch === 'x64') {
|
|
265
|
+
if (isMusl()) {
|
|
266
|
+
try {
|
|
267
|
+
return require('./line-bot-sdk-rs.linux-x64-musl.node')
|
|
268
|
+
} catch (e) {
|
|
269
|
+
loadErrors.push(e)
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const binding = require('line-bot-sdk-rs-linux-x64-musl')
|
|
273
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-x64-musl/package.json').version
|
|
274
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
|
+
}
|
|
277
|
+
return binding
|
|
278
|
+
} catch (e) {
|
|
279
|
+
loadErrors.push(e)
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
try {
|
|
283
|
+
return require('./line-bot-sdk-rs.linux-x64-gnu.node')
|
|
284
|
+
} catch (e) {
|
|
285
|
+
loadErrors.push(e)
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
const binding = require('line-bot-sdk-rs-linux-x64-gnu')
|
|
289
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-x64-gnu/package.json').version
|
|
290
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
|
+
}
|
|
293
|
+
return binding
|
|
294
|
+
} catch (e) {
|
|
295
|
+
loadErrors.push(e)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} else if (process.arch === 'arm64') {
|
|
299
|
+
if (isMusl()) {
|
|
300
|
+
try {
|
|
301
|
+
return require('./line-bot-sdk-rs.linux-arm64-musl.node')
|
|
302
|
+
} catch (e) {
|
|
303
|
+
loadErrors.push(e)
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const binding = require('line-bot-sdk-rs-linux-arm64-musl')
|
|
307
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-arm64-musl/package.json').version
|
|
308
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
|
+
}
|
|
311
|
+
return binding
|
|
312
|
+
} catch (e) {
|
|
313
|
+
loadErrors.push(e)
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
try {
|
|
317
|
+
return require('./line-bot-sdk-rs.linux-arm64-gnu.node')
|
|
318
|
+
} catch (e) {
|
|
319
|
+
loadErrors.push(e)
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
const binding = require('line-bot-sdk-rs-linux-arm64-gnu')
|
|
323
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-arm64-gnu/package.json').version
|
|
324
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
|
+
}
|
|
327
|
+
return binding
|
|
328
|
+
} catch (e) {
|
|
329
|
+
loadErrors.push(e)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
} else if (process.arch === 'arm') {
|
|
333
|
+
if (isMusl()) {
|
|
334
|
+
try {
|
|
335
|
+
return require('./line-bot-sdk-rs.linux-arm-musleabihf.node')
|
|
336
|
+
} catch (e) {
|
|
337
|
+
loadErrors.push(e)
|
|
338
|
+
}
|
|
339
|
+
try {
|
|
340
|
+
const binding = require('line-bot-sdk-rs-linux-arm-musleabihf')
|
|
341
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-arm-musleabihf/package.json').version
|
|
342
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
|
+
}
|
|
345
|
+
return binding
|
|
346
|
+
} catch (e) {
|
|
347
|
+
loadErrors.push(e)
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
try {
|
|
351
|
+
return require('./line-bot-sdk-rs.linux-arm-gnueabihf.node')
|
|
352
|
+
} catch (e) {
|
|
353
|
+
loadErrors.push(e)
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
const binding = require('line-bot-sdk-rs-linux-arm-gnueabihf')
|
|
357
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-arm-gnueabihf/package.json').version
|
|
358
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
|
+
}
|
|
361
|
+
return binding
|
|
362
|
+
} catch (e) {
|
|
363
|
+
loadErrors.push(e)
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
} else if (process.arch === 'loong64') {
|
|
367
|
+
if (isMusl()) {
|
|
368
|
+
try {
|
|
369
|
+
return require('./line-bot-sdk-rs.linux-loong64-musl.node')
|
|
370
|
+
} catch (e) {
|
|
371
|
+
loadErrors.push(e)
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
const binding = require('line-bot-sdk-rs-linux-loong64-musl')
|
|
375
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-loong64-musl/package.json').version
|
|
376
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
|
+
}
|
|
379
|
+
return binding
|
|
380
|
+
} catch (e) {
|
|
381
|
+
loadErrors.push(e)
|
|
382
|
+
}
|
|
383
|
+
} else {
|
|
384
|
+
try {
|
|
385
|
+
return require('./line-bot-sdk-rs.linux-loong64-gnu.node')
|
|
386
|
+
} catch (e) {
|
|
387
|
+
loadErrors.push(e)
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const binding = require('line-bot-sdk-rs-linux-loong64-gnu')
|
|
391
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-loong64-gnu/package.json').version
|
|
392
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
|
+
}
|
|
395
|
+
return binding
|
|
396
|
+
} catch (e) {
|
|
397
|
+
loadErrors.push(e)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
} else if (process.arch === 'riscv64') {
|
|
401
|
+
if (isMusl()) {
|
|
402
|
+
try {
|
|
403
|
+
return require('./line-bot-sdk-rs.linux-riscv64-musl.node')
|
|
404
|
+
} catch (e) {
|
|
405
|
+
loadErrors.push(e)
|
|
406
|
+
}
|
|
407
|
+
try {
|
|
408
|
+
const binding = require('line-bot-sdk-rs-linux-riscv64-musl')
|
|
409
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-riscv64-musl/package.json').version
|
|
410
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
|
+
}
|
|
413
|
+
return binding
|
|
414
|
+
} catch (e) {
|
|
415
|
+
loadErrors.push(e)
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
try {
|
|
419
|
+
return require('./line-bot-sdk-rs.linux-riscv64-gnu.node')
|
|
420
|
+
} catch (e) {
|
|
421
|
+
loadErrors.push(e)
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
const binding = require('line-bot-sdk-rs-linux-riscv64-gnu')
|
|
425
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-riscv64-gnu/package.json').version
|
|
426
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
|
+
}
|
|
429
|
+
return binding
|
|
430
|
+
} catch (e) {
|
|
431
|
+
loadErrors.push(e)
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
} else if (process.arch === 'ppc64') {
|
|
435
|
+
try {
|
|
436
|
+
return require('./line-bot-sdk-rs.linux-ppc64-gnu.node')
|
|
437
|
+
} catch (e) {
|
|
438
|
+
loadErrors.push(e)
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
const binding = require('line-bot-sdk-rs-linux-ppc64-gnu')
|
|
442
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-ppc64-gnu/package.json').version
|
|
443
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
|
+
}
|
|
446
|
+
return binding
|
|
447
|
+
} catch (e) {
|
|
448
|
+
loadErrors.push(e)
|
|
449
|
+
}
|
|
450
|
+
} else if (process.arch === 's390x') {
|
|
451
|
+
try {
|
|
452
|
+
return require('./line-bot-sdk-rs.linux-s390x-gnu.node')
|
|
453
|
+
} catch (e) {
|
|
454
|
+
loadErrors.push(e)
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
const binding = require('line-bot-sdk-rs-linux-s390x-gnu')
|
|
458
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-linux-s390x-gnu/package.json').version
|
|
459
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
|
+
}
|
|
462
|
+
return binding
|
|
463
|
+
} catch (e) {
|
|
464
|
+
loadErrors.push(e)
|
|
465
|
+
}
|
|
466
|
+
} else {
|
|
467
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
468
|
+
}
|
|
469
|
+
} else if (process.platform === 'openharmony') {
|
|
470
|
+
if (process.arch === 'arm64') {
|
|
471
|
+
try {
|
|
472
|
+
return require('./line-bot-sdk-rs.openharmony-arm64.node')
|
|
473
|
+
} catch (e) {
|
|
474
|
+
loadErrors.push(e)
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
const binding = require('line-bot-sdk-rs-openharmony-arm64')
|
|
478
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-openharmony-arm64/package.json').version
|
|
479
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
|
+
}
|
|
482
|
+
return binding
|
|
483
|
+
} catch (e) {
|
|
484
|
+
loadErrors.push(e)
|
|
485
|
+
}
|
|
486
|
+
} else if (process.arch === 'x64') {
|
|
487
|
+
try {
|
|
488
|
+
return require('./line-bot-sdk-rs.openharmony-x64.node')
|
|
489
|
+
} catch (e) {
|
|
490
|
+
loadErrors.push(e)
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
const binding = require('line-bot-sdk-rs-openharmony-x64')
|
|
494
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-openharmony-x64/package.json').version
|
|
495
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
|
+
}
|
|
498
|
+
return binding
|
|
499
|
+
} catch (e) {
|
|
500
|
+
loadErrors.push(e)
|
|
501
|
+
}
|
|
502
|
+
} else if (process.arch === 'arm') {
|
|
503
|
+
try {
|
|
504
|
+
return require('./line-bot-sdk-rs.openharmony-arm.node')
|
|
505
|
+
} catch (e) {
|
|
506
|
+
loadErrors.push(e)
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
const binding = require('line-bot-sdk-rs-openharmony-arm')
|
|
510
|
+
const bindingPackageVersion = require('line-bot-sdk-rs-openharmony-arm/package.json').version
|
|
511
|
+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
|
+
}
|
|
514
|
+
return binding
|
|
515
|
+
} catch (e) {
|
|
516
|
+
loadErrors.push(e)
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
nativeBinding = requireNative()
|
|
527
|
+
|
|
528
|
+
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
529
|
+
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
530
|
+
// 'true' → force WASI fallback even if native loaded
|
|
531
|
+
// 'error' → force WASI and throw if no WASI binding is found
|
|
532
|
+
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
533
|
+
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
534
|
+
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
535
|
+
const forceWasi =
|
|
536
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' || process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
537
|
+
|
|
538
|
+
if (!nativeBinding || forceWasi) {
|
|
539
|
+
let wasiBinding = null
|
|
540
|
+
let wasiBindingError = null
|
|
541
|
+
try {
|
|
542
|
+
wasiBinding = require('./line-bot-sdk-rs.wasi.cjs')
|
|
543
|
+
nativeBinding = wasiBinding
|
|
544
|
+
} catch (err) {
|
|
545
|
+
if (forceWasi) {
|
|
546
|
+
wasiBindingError = err
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (!nativeBinding || forceWasi) {
|
|
550
|
+
try {
|
|
551
|
+
wasiBinding = require('line-bot-sdk-rs-wasm32-wasi')
|
|
552
|
+
nativeBinding = wasiBinding
|
|
553
|
+
} catch (err) {
|
|
554
|
+
if (forceWasi) {
|
|
555
|
+
if (!wasiBindingError) {
|
|
556
|
+
wasiBindingError = err
|
|
557
|
+
} else {
|
|
558
|
+
wasiBindingError.cause = err
|
|
559
|
+
}
|
|
560
|
+
loadErrors.push(err)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
565
|
+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
566
|
+
error.cause = wasiBindingError
|
|
567
|
+
throw error
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (!nativeBinding) {
|
|
572
|
+
if (loadErrors.length > 0) {
|
|
573
|
+
throw new Error(
|
|
574
|
+
`Cannot find native binding. ` +
|
|
575
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
576
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
577
|
+
{
|
|
578
|
+
cause: loadErrors.reduce((err, cur) => {
|
|
579
|
+
cur.cause = err
|
|
580
|
+
return cur
|
|
581
|
+
}),
|
|
582
|
+
},
|
|
583
|
+
)
|
|
584
|
+
}
|
|
585
|
+
throw new Error(`Failed to load native binding`)
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
module.exports = nativeBinding
|
|
589
|
+
module.exports.LineClient = nativeBinding.LineClient
|
|
590
|
+
module.exports.parseWebhookBody = nativeBinding.parseWebhookBody
|
|
591
|
+
module.exports.verifyWebhookSignature = nativeBinding.verifyWebhookSignature
|
package/package.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "line-bot-sdk-rs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "High-performance LINE Messaging API SDK built with Rust and NAPI-RS",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"line",
|
|
9
|
+
"line-bot",
|
|
10
|
+
"line-messaging-api",
|
|
11
|
+
"line-sdk",
|
|
12
|
+
"napi-rs",
|
|
13
|
+
"rust"
|
|
14
|
+
],
|
|
15
|
+
"files": [
|
|
16
|
+
"index.d.ts",
|
|
17
|
+
"index.js"
|
|
18
|
+
],
|
|
19
|
+
"napi": {
|
|
20
|
+
"binaryName": "line-bot-sdk-rs",
|
|
21
|
+
"targets": [
|
|
22
|
+
"x86_64-pc-windows-msvc",
|
|
23
|
+
"x86_64-apple-darwin",
|
|
24
|
+
"x86_64-unknown-linux-gnu",
|
|
25
|
+
"aarch64-apple-darwin"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">= 18.17.0 < 19 || >= 20.3.0 < 21 || >= 21.1.0"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"registry": "https://registry.npmjs.org/",
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"artifacts": "napi artifacts",
|
|
37
|
+
"bench": "node --import @oxc-node/core/register benchmark/bench.ts",
|
|
38
|
+
"build": "napi build --platform --release",
|
|
39
|
+
"build:debug": "napi build --platform",
|
|
40
|
+
"format": "run-p format:prettier format:rs format:toml",
|
|
41
|
+
"format:prettier": "prettier . -w",
|
|
42
|
+
"format:toml": "taplo format",
|
|
43
|
+
"format:rs": "cargo fmt",
|
|
44
|
+
"lint": "oxlint .",
|
|
45
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
46
|
+
"test": "ava",
|
|
47
|
+
"preversion": "napi build --platform && git add .",
|
|
48
|
+
"version": "napi version",
|
|
49
|
+
"prepare": "husky"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@emnapi/core": "^1.5.0",
|
|
53
|
+
"@emnapi/runtime": "^1.5.0",
|
|
54
|
+
"@napi-rs/cli": "^3.2.0",
|
|
55
|
+
"@oxc-node/core": "^0.1.0",
|
|
56
|
+
"@taplo/cli": "^0.7.0",
|
|
57
|
+
"@tybys/wasm-util": "^0.10.0",
|
|
58
|
+
"@types/node": "^25.9.3",
|
|
59
|
+
"ava": "^8.0.0",
|
|
60
|
+
"chalk": "^5.6.2",
|
|
61
|
+
"husky": "^9.1.7",
|
|
62
|
+
"lint-staged": "^17.0.0",
|
|
63
|
+
"npm-run-all2": "^8.0.4",
|
|
64
|
+
"oxlint": "^1.14.0",
|
|
65
|
+
"prettier": "^3.6.2",
|
|
66
|
+
"tinybench": "^6.0.0",
|
|
67
|
+
"typescript": "^6.0.0"
|
|
68
|
+
},
|
|
69
|
+
"lint-staged": {
|
|
70
|
+
"*.@(js|ts|tsx)": [
|
|
71
|
+
"oxlint --fix"
|
|
72
|
+
],
|
|
73
|
+
"*.@(js|ts|tsx|yml|yaml|md|json)": [
|
|
74
|
+
"prettier --write"
|
|
75
|
+
],
|
|
76
|
+
"*.toml": [
|
|
77
|
+
"taplo format"
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
"ava": {
|
|
81
|
+
"extensions": [
|
|
82
|
+
"ts"
|
|
83
|
+
],
|
|
84
|
+
"timeout": "2m",
|
|
85
|
+
"workerThreads": false,
|
|
86
|
+
"environmentVariables": {
|
|
87
|
+
"OXC_TSCONFIG_PATH": "./__test__/tsconfig.json"
|
|
88
|
+
},
|
|
89
|
+
"nodeArguments": [
|
|
90
|
+
"--import",
|
|
91
|
+
"@oxc-node/core/register"
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
"prettier": {
|
|
95
|
+
"printWidth": 120,
|
|
96
|
+
"semi": false,
|
|
97
|
+
"trailingComma": "all",
|
|
98
|
+
"singleQuote": true,
|
|
99
|
+
"arrowParens": "always"
|
|
100
|
+
},
|
|
101
|
+
"packageManager": "yarn@4.14.1",
|
|
102
|
+
"optionalDependencies": {
|
|
103
|
+
"line-bot-sdk-rs-win32-x64-msvc": "1.0.0",
|
|
104
|
+
"line-bot-sdk-rs-darwin-x64": "1.0.0",
|
|
105
|
+
"line-bot-sdk-rs-linux-x64-gnu": "1.0.0",
|
|
106
|
+
"line-bot-sdk-rs-darwin-arm64": "1.0.0"
|
|
107
|
+
}
|
|
108
|
+
}
|