Skip to content

Commit

Permalink
fix(webhook): craeteTextMessage() with contents must provide altText
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Oct 16, 2023
1 parent a0e933c commit c84199b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/webhook/handlers/askingArticleSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const askingArticleSource: ChatbotStateHandler = async (params) => {
case POSTBACK_NO:
replies = [
createTextMessage({
altText: t`Instructions`,
contents: [
{
type: 'span',
Expand Down
13 changes: 10 additions & 3 deletions src/webhook/handlers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,17 @@ export function createCommentBubble(articleId: string): FlexBubble {
}

/**
* Omit<> breaks FlexText's union, thus we Omit<> separately and then union back
* Omit<> breaks FlexText's discriminated union, thus we Omit<> separately and then union back
*/
type FlexTextWithoutType =
| Omit<FlexText & { text?: never; contents: FlexSpan[] }, 'type'>
| Omit<
FlexText & {
/* Discriminator */ text?: never;
contents: FlexSpan[];
/* Must be supplied in this case */ altText: string;
},
'type'
>
| Omit<FlexText & { text: string; contents?: never }, 'type'>;

/**
Expand All @@ -710,7 +717,7 @@ type FlexTextWithoutType =
export function createTextMessage(textProps: FlexTextWithoutType): FlexMessage {
return {
type: 'flex',
altText: textProps.text ?? '',
altText: textProps.text ?? textProps.altText,
contents: {
type: 'bubble',
body: {
Expand Down

0 comments on commit c84199b

Please sign in to comment.