refactor(line): centralize action helpers

This commit is contained in:
Peter Steinberger
2026-02-14 13:35:04 +00:00
parent 25ecd4216c
commit d71f6afb7f
3 changed files with 72 additions and 116 deletions

61
src/line/actions.ts Normal file
View File

@@ -0,0 +1,61 @@
import type { messagingApi } from "@line/bot-sdk";
export type Action = messagingApi.Action;
/**
* Create a message action (sends text when tapped)
*/
export function messageAction(label: string, text?: string): Action {
return {
type: "message",
label: label.slice(0, 20),
text: text ?? label,
};
}
/**
* Create a URI action (opens a URL when tapped)
*/
export function uriAction(label: string, uri: string): Action {
return {
type: "uri",
label: label.slice(0, 20),
uri,
};
}
/**
* Create a postback action (sends data to webhook when tapped)
*/
export function postbackAction(label: string, data: string, displayText?: string): Action {
return {
type: "postback",
label: label.slice(0, 20),
data: data.slice(0, 300),
displayText: displayText?.slice(0, 300),
};
}
/**
* Create a datetime picker action
*/
export function datetimePickerAction(
label: string,
data: string,
mode: "date" | "time" | "datetime",
options?: {
initial?: string;
max?: string;
min?: string;
},
): Action {
return {
type: "datetimepicker",
label: label.slice(0, 20),
data: data.slice(0, 300),
mode,
initial: options?.initial,
max: options?.max,
min: options?.min,
};
}