Skip to content

fix(line): map inbound message types to the correct MessageType - #39485

Merged
teknium1 merged 1 commit into
mainfrom
salvage/38528-line-message-type
Jun 5, 2026
Merged

fix(line): map inbound message types to the correct MessageType#39485
teknium1 merged 1 commit into
mainfrom
salvage/38528-line-message-type

Conversation

@teknium1

@teknium1 teknium1 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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.py built every non-text inbound MessageEvent with message_type=MessageType.IMAGE. That enum member doesn't exist (the enum has PHOTO, not IMAGE), so every image/video/audio/file/sticker/location message raised AttributeError at construction time.

Changes

  • plugins/platforms/line/adapter.py: replace the IMAGE/TEXT ternary with a _LINE_MESSAGE_TYPES lookup table mapping each LINE webhook type to its proper MessageType (image→PHOTO, video→VIDEO, audio→VOICE, file→DOCUMENT, location→LOCATION, sticker→STICKER), unknown types fall back to TEXT.
  • tests/gateway/test_line_plugin.py: add TestMessageTypeMapping — regression guard for the missing IMAGE member 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 on MessageType — 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

Before After
Non-text LINE message AttributeError: IMAGE classified correctly
tests/gateway/test_line_plugin.py 76 passed

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>
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/38528-line-message-type vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9849 on HEAD, 9850 on base (✅ -1)

🆕 New issues: none

✅ Fixed issues (1):

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.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins labels Jun 5, 2026
@teknium1
teknium1 merged commit 7309f3b into main Jun 5, 2026
23 checks passed
@teknium1
teknium1 deleted the salvage/38528-line-message-type branch June 5, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants