@@ -14,7 +14,7 @@ import { messageAction, normalizeLineMessageActions } from "./actions.js";
1414import { resolveLineChannelAccessToken } from "./channel-access-token.js" ;
1515import { validateLineMediaUrl } from "./outbound-media.js" ;
1616import { createLineSendReceipt } from "./send-receipt.js" ;
17- import type { LineOutboundMediaKind , LineSendResult } from "./types.js" ;
17+ import type { LineChannelData , LineOutboundMediaKind , LineSendResult } from "./types.js" ;
1818
1919type Message = messagingApi . Message ;
2020type TextMessage = messagingApi . TextMessage ;
@@ -26,6 +26,7 @@ type FlexContainer = messagingApi.FlexContainer;
2626type TemplateMessage = messagingApi . TemplateMessage ;
2727type QuickReply = messagingApi . QuickReply ;
2828type QuickReplyItem = messagingApi . QuickReplyItem ;
29+ type LineLocation = NonNullable < LineChannelData [ "location" ] > ;
2930
3031const userProfileCache = new Map <
3132 string ,
@@ -241,12 +242,16 @@ export function createAudioMessage(originalContentUrl: string, durationMs: numbe
241242 } ;
242243}
243244
244- export function createLocationMessage ( location : {
245- title : string ;
246- address : string ;
247- latitude : number ;
248- longitude : number ;
249- } ) : LocationMessage {
245+ function isValidLineLocation ( location : LineLocation ) : boolean {
246+ // LINE rejects either blank required field atomically, so every delivery path
247+ // must use this gate before adding a location to a provider request.
248+ return location . title . trim ( ) . length > 0 && location . address . trim ( ) . length > 0 ;
249+ }
250+
251+ export function createLocationMessage ( location : LineLocation ) : LocationMessage | null {
252+ if ( ! isValidLineLocation ( location ) ) {
253+ return null ;
254+ }
250255 return {
251256 type : "location" ,
252257 title : truncateUtf16Safe ( location . title , 100 ) ,
@@ -503,15 +508,14 @@ export async function pushImageMessage(
503508
504509export async function pushLocationMessage (
505510 to : string ,
506- location : {
507- title : string ;
508- address : string ;
509- latitude : number ;
510- longitude : number ;
511- } ,
511+ location : LineLocation ,
512512 opts : LinePushOpts ,
513513) : Promise < LineSendResult > {
514- return pushLineMessages ( to , [ createLocationMessage ( location ) ] , opts , {
514+ const message = createLocationMessage ( location ) ;
515+ if ( ! message ) {
516+ throw new Error ( "LINE location title and address must be non-empty" ) ;
517+ }
518+ return pushLineMessages ( to , [ message ] , opts , {
515519 verboseMessage : ( chatId ) => `line: pushed location to ${ chatId } ` ,
516520 } ) ;
517521}
0 commit comments