-
Notifications
You must be signed in to change notification settings - Fork 171
feat(imessage): receive mini-app content #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |
| asContact, | ||
| asCustom, | ||
| asReply, | ||
| asResolvedApp, | ||
| asText, | ||
| asVoice, | ||
| createLogger, | ||
|
|
@@ -252,12 +253,47 @@ const buildOrderedPartMessage = async ( | |
| const unsupportedMessageContent = (): Content => | ||
| asCustom({ imessage_type: "unsupported-message" }); | ||
|
|
||
| const toMiniAppContent = ( | ||
| client: AdvancedIMessage, | ||
| message: AppleMessage | ||
| ): Content | undefined => { | ||
| const miniApp = message.content.miniApp; | ||
| if (!(miniApp?.url && miniApp.layout)) { | ||
| return; | ||
| } | ||
|
|
||
| const imageAttachment = messageAttachments(message).find((attachment) => | ||
| normalizeAppleAttachmentMimeType(attachment).startsWith("image/") | ||
| ); | ||
|
Comment on lines
+256
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good receive mapping overall: require both Minor edge case: image bytes come from the first |
||
| const layout = imageAttachment | ||
| ? async () => ({ | ||
| ...miniApp.layout, | ||
| image: Uint8Array.from( | ||
| await downloadPrimaryAttachment(client, imageAttachment.guid) | ||
| ), | ||
| }) | ||
| : miniApp.layout; | ||
|
|
||
| return asResolvedApp(miniApp.url, layout, { | ||
| live: miniApp.live, | ||
| }); | ||
| }; | ||
|
|
||
| const buildUnwrappedContentMessage = async ( | ||
| client: AdvancedIMessage, | ||
| base: RemoteMessageBase, | ||
| message: AppleMessage, | ||
| messageGuidStr: string | ||
| ): Promise<IMessageMessage> => { | ||
| const miniAppContent = toMiniAppContent(client, message); | ||
| if (miniAppContent) { | ||
| return { | ||
| ...base, | ||
| id: messageGuidStr, | ||
| content: miniAppContent, | ||
| }; | ||
| } | ||
|
|
||
| const attachments = messageAttachments(message); | ||
| const voiceAttachmentGuid = message.isAudioMessage | ||
| ? attachments.find((attachment) => appleAudioMimeType(attachment))?.guid | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key root-cause fix, not a workaround: inbound native cards already have a decoded layout, so reusing
asApp(URL scrape / Open Graph) would invent or overwrite sender-provided card data.One intentional tradeoff here: this path validates with the looser base schema and skips the stricter authoring refinements (visible slot required, image/title pairing). That seems right for “preserve what Apple sent,” but inbound
applayouts may be weaker than outbound ones.