refactor(line): use official LINE Bot SDK v8#2413
Open
ex-takashima wants to merge 1 commit intosipeed:mainfrom
Open
refactor(line): use official LINE Bot SDK v8#2413ex-takashima wants to merge 1 commit intosipeed:mainfrom
ex-takashima wants to merge 1 commit intosipeed:mainfrom
Conversation
Replace hand-rolled HTTP/HMAC/JSON code (~270 lines) with the official line-bot-sdk-go v8, reducing maintenance burden and eliminating potential bugs in signature verification, request construction, and response parsing. This continues the work started in sipeed#500 by @xiaket, addressing all review feedback and rebasing onto current main. Changes: - Replace bytes/crypto/json/io imports with line-bot-sdk-go/v8 - Use webhook.ParseRequest for body reading + signature verification - Use messaging_api.MessagingApiAPI for ReplyMessage/PushMessage/ShowLoadingAnimation/GetBotInfo - Type-switch on webhook.MessageEvent message types (TextMessageContent, ImageMessageContent, etc.) instead of JSON unmarshalling - Type-switch on webhook.SourceInterface (UserSource/GroupSource/RoomSource) - Type-switch on webhook.Mentionee (UserMentionee/AllMentionee) Review feedback addressed (from sipeed#500): - Use WithContext(ctx) on all SDK calls to preserve cancellation/timeout - Fix variable shadowing of isMentioned (declared at function scope) - Remove reflect-based message ID extraction (use type switch + msg.Id) - Use mentionee.IsSelf for cleaner bot mention detection - Preserve body size security check via http.MaxBytesReader before webhook.ParseRequest (compatible with sipeed#1413) All existing tests pass without modification.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Replace hand-rolled HTTP/HMAC/JSON code (~270 lines) in the LINE channel with the official
line-bot-sdk-gov8, reducing maintenance burden and eliminating potential bugs in signature verification, request construction, and response parsing.This continues the work from #500 by @xiaket, which has been inactive for over a month. With @yinwm's encouragement (#500 (review)), I've rebased onto current main and addressed all review feedback.
🗣️ Type of Change
🤖 AI Code Generation
Changes
bytes/crypto/encoding/json/ioimports withline-bot-sdk-go/v8webhook.ParseRequestfor body reading + signature verificationmessaging_api.MessagingApiAPIforReplyMessage/PushMessage/ShowLoadingAnimation/GetBotInfowebhook.MessageEventmessage types (TextMessageContent,ImageMessageContent, etc.)webhook.SourceInterface(UserSource/GroupSource/RoomSource)webhook.Mentionee(UserMentionee/AllMentionee)Net change: +174 / −295 lines in
pkg/channels/line/line.go.Review feedback addressed (from #500)
WithContext(ctx)on all SDK callsisMentionedreflect-based message ID extractionmsg.Iddirectlyr.Bodywithhttp.MaxBytesReaderbeforewebhook.ParseRequest; check for*http.MaxBytesErrorto return413mentionee.IsSelf(new SDK field) for cleaner bot detection☑️ Checklist
go test ./pkg/channels/line/...)Test plan
go build ./pkg/channels/line/go test ./pkg/channels/line/ -v— 5/5 tests passlinux/arm64worksNotes