Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #425 from beabee-communityrm/feat/telegram-content…
Browse files Browse the repository at this point in the history
…-v0.14.x

feat: add Telegram content to v0.14.x
  • Loading branch information
wpf500 authored May 15, 2024
2 parents 3fa2782 + 8d7df93 commit a5092e0
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
12 changes: 11 additions & 1 deletion src/api/controllers/ContentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
GetJoinContentDto,
GetJoinSetupContentDto,
GetProfileContentDto,
GetShareContentDto
GetShareContentDto,
GetTelegramContentDto
} from "@api/dto/ContentDto";
import { ContentParams } from "@api/params/ContentParams";
import ContentTransformer from "@api/transformers/ContentTransformer";
Expand Down Expand Up @@ -90,4 +91,13 @@ export class ContentController {
ContentTransformer.updateOne("share", data);
return ContentTransformer.fetchOne("share");
}

@Authorized("admin")
@Patch("/telegram")
async updateTelegram(
@PartialBody() data: GetTelegramContentDto
): Promise<GetTelegramContentDto> {
await ContentTransformer.updateOne("telegram", data);
return ContentTransformer.fetchOne("telegram");
}
}
13 changes: 11 additions & 2 deletions src/api/dto/ContentDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
JoinContentPeriodData,
JoinSetupContentData,
ProfileContentData,
ShareContentData
ShareContentData,
TelegramContentData
} from "@type/content-data";
import { ContentId } from "@type/content-id";

Expand Down Expand Up @@ -195,6 +196,12 @@ export class GetShareContentDto implements ShareContentData {
twitterHandle!: string;
}

export class GetTelegramContentDto implements TelegramContentData {
/** Markdown formatted welcome message */
@IsString()
welcomeMessageMd!: string;
}

export type GetContentDto<Id extends ContentId = ContentId> =
Id extends "contacts"
? GetContactsContentDto
Expand All @@ -210,4 +217,6 @@ export type GetContentDto<Id extends ContentId = ContentId> =
? GetProfileContentDto
: never | Id extends "share"
? GetShareContentDto
: never;
: never | Id extends "telegram"
? GetTelegramContentDto
: never;
3 changes: 2 additions & 1 deletion src/api/params/ContentParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class ContentParams {
"join",
"join/setup",
"profile",
"share"
"share",
"telegram"
] satisfies ContentId[])
id!: ContentId;
}
12 changes: 10 additions & 2 deletions src/api/transformers/ContentTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
GetJoinContentDto,
GetJoinSetupContentDto,
GetProfileContentDto,
GetShareContentDto
GetShareContentDto,
GetTelegramContentDto
} from "@api/dto/ContentDto";

import Content from "@models/Content";
Expand All @@ -34,7 +35,8 @@ class ContentTransformer {
join: GetJoinContentDto,
"join/setup": GetJoinSetupContentDto,
profile: GetProfileContentDto,
share: GetShareContentDto
share: GetShareContentDto,
telegram: GetTelegramContentDto
}[id];

return plainToInstance(Dto as any, data);
Expand Down Expand Up @@ -203,6 +205,12 @@ const contentData = {
image: ["option", "share-image", "text"],
title: ["option", "share-title", "text"],
twitterHandle: ["option", "share-twitter-handle", "text"]
}),
telegram: withValue<"telegram">({
welcomeMessageMd: [
"data",
"*Hello*, I'm your Callout bot\\. Use me to list and answer callouts from [beabee](https://beabee.io/)\\."
]
})
} as const;

Expand Down
6 changes: 4 additions & 2 deletions src/apps/settings/apps/content/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ app.get(
general: get("general"),
join: get("join"),
joinSetup: get("join/setup"),
profile: get("profile")
profile: get("profile"),
telegram: get("telegram")
});
})
);
Expand Down Expand Up @@ -57,7 +58,8 @@ const parseData = {
profile: (d: any) => d,
contacts: (d: any) => d,
share: (d: any) => d,
email: (d: any) => d
email: (d: any) => d,
telegram: (d: any) => d
} as const;

// urlencoding parser doesn't support overwriting if the same query param
Expand Down
8 changes: 7 additions & 1 deletion src/type/content-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export interface ShareContentData {
twitterHandle: string;
}

export interface TelegramContentData {
welcomeMessageMd: string;
}

export type ContentData<Id extends ContentId = ContentId> =
Id extends "contacts"
? ContactsContentData
Expand All @@ -100,4 +104,6 @@ export type ContentData<Id extends ContentId = ContentId> =
? ProfileContentData
: never | Id extends "share"
? ShareContentData
: never;
: never | Id extends "telegram"
? TelegramContentData
: never;
3 changes: 2 additions & 1 deletion src/type/content-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export type ContentId =
| "general"
| "contacts"
| "share"
| "email";
| "email"
| "telegram";

0 comments on commit a5092e0

Please sign in to comment.