fix(line): map inbound message types to the correct MessageType - #39485
Merged
Conversation
The LINE adapter classified every non-text inbound message as `MessageType.IMAGE`, which doesn't exist on the enum — so any image, video, audio, file, sticker, or location message raised AttributeError the moment it was constructed. Beyond fixing the crash, every non-text message was being collapsed onto a single type. The gateway routes on MessageType (voice → STT, files → document handling, etc.), so misclassification silently mishandled media. Replace the inline ternary with a `_LINE_MESSAGE_TYPES` lookup that maps each LINE webhook type to its proper enum member (audio → VOICE to match how Telegram/WhatsApp treat voice notes), falling back to TEXT for unknown types. Adds regression tests covering the mapping and the old AttributeError. Co-authored-by: Sahibzada Allahyar <94376830+sahibzada-allahyar@users.noreply.github.com>
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-attribute |
1 |
First entries
plugins/platforms/line/adapter.py:971: [unresolved-attribute] unresolved-attribute: Class `MessageType` has no attribute `IMAGE`
Unchanged: 5106 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
1 task
1 task
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.
Summary
Non-text LINE messages no longer crash, and they're now classified as the correct media type instead of all being treated as images.
Salvages #38528 (@sahibzada-allahyar), with a wider fix on top.
Root cause
plugins/platforms/line/adapter.pybuilt every non-text inboundMessageEventwithmessage_type=MessageType.IMAGE. That enum member doesn't exist (the enum hasPHOTO, notIMAGE), so every image/video/audio/file/sticker/location message raisedAttributeErrorat construction time.Changes
plugins/platforms/line/adapter.py: replace theIMAGE/TEXTternary with a_LINE_MESSAGE_TYPESlookup table mapping each LINE webhook type to its properMessageType(image→PHOTO,video→VIDEO,audio→VOICE,file→DOCUMENT,location→LOCATION,sticker→STICKER), unknown types fall back toTEXT.tests/gateway/test_line_plugin.py: addTestMessageTypeMapping— regression guard for the missingIMAGEmember plus full mapping coverage.Why wider than the original
@sahibzada-allahyar's PR correctly swapped
IMAGE→PHOTO, which stops the crash. But the surrounding code still mapped all non-text messages to one type. The gateway routes onMessageType— voice notes go through STT, files through document handling — so a LINE voice clip or PDF was being mishandled as a photo. The lookup table gives each type its correct classification, matching how the WhatsApp/Telegram/BlueBubbles adapters already do it.Validation
AttributeError: IMAGEtests/gateway/test_line_plugin.py