From 8d7df932ca1dee12e895c3647ae9cf7defc14d44 Mon Sep 17 00:00:00 2001 From: Will Franklin Date: Wed, 15 May 2024 17:26:05 +0100 Subject: [PATCH] Add Telegram content --- src/api/controllers/ContentController.ts | 12 +++++++++++- src/api/dto/ContentDto.ts | 13 +++++++++++-- src/api/params/ContentParams.ts | 3 ++- src/api/transformers/ContentTransformer.ts | 12 ++++++++++-- src/apps/settings/apps/content/app.ts | 6 ++++-- src/type/content-data.ts | 8 +++++++- src/type/content-id.ts | 3 ++- 7 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/api/controllers/ContentController.ts b/src/api/controllers/ContentController.ts index c3d199478..c7be096f3 100644 --- a/src/api/controllers/ContentController.ts +++ b/src/api/controllers/ContentController.ts @@ -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"; @@ -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 { + await ContentTransformer.updateOne("telegram", data); + return ContentTransformer.fetchOne("telegram"); + } } diff --git a/src/api/dto/ContentDto.ts b/src/api/dto/ContentDto.ts index 661356151..6a7d90157 100644 --- a/src/api/dto/ContentDto.ts +++ b/src/api/dto/ContentDto.ts @@ -26,7 +26,8 @@ import { JoinContentPeriodData, JoinSetupContentData, ProfileContentData, - ShareContentData + ShareContentData, + TelegramContentData } from "@type/content-data"; import { ContentId } from "@type/content-id"; @@ -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 "contacts" ? GetContactsContentDto @@ -210,4 +217,6 @@ export type GetContentDto = ? GetProfileContentDto : never | Id extends "share" ? GetShareContentDto - : never; + : never | Id extends "telegram" + ? GetTelegramContentDto + : never; diff --git a/src/api/params/ContentParams.ts b/src/api/params/ContentParams.ts index 7e02087ce..39ce45d62 100644 --- a/src/api/params/ContentParams.ts +++ b/src/api/params/ContentParams.ts @@ -9,7 +9,8 @@ export class ContentParams { "join", "join/setup", "profile", - "share" + "share", + "telegram" ] satisfies ContentId[]) id!: ContentId; } diff --git a/src/api/transformers/ContentTransformer.ts b/src/api/transformers/ContentTransformer.ts index 1492b086b..16dd0a7ca 100644 --- a/src/api/transformers/ContentTransformer.ts +++ b/src/api/transformers/ContentTransformer.ts @@ -12,7 +12,8 @@ import { GetJoinContentDto, GetJoinSetupContentDto, GetProfileContentDto, - GetShareContentDto + GetShareContentDto, + GetTelegramContentDto } from "@api/dto/ContentDto"; import Content from "@models/Content"; @@ -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); @@ -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; diff --git a/src/apps/settings/apps/content/app.ts b/src/apps/settings/apps/content/app.ts index c4ccae529..3e304677f 100644 --- a/src/apps/settings/apps/content/app.ts +++ b/src/apps/settings/apps/content/app.ts @@ -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") }); }) ); @@ -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 diff --git a/src/type/content-data.ts b/src/type/content-data.ts index 48a2d3ea2..12d94ead1 100644 --- a/src/type/content-data.ts +++ b/src/type/content-data.ts @@ -85,6 +85,10 @@ export interface ShareContentData { twitterHandle: string; } +export interface TelegramContentData { + welcomeMessageMd: string; +} + export type ContentData = Id extends "contacts" ? ContactsContentData @@ -100,4 +104,6 @@ export type ContentData = ? ProfileContentData : never | Id extends "share" ? ShareContentData - : never; + : never | Id extends "telegram" + ? TelegramContentData + : never; diff --git a/src/type/content-id.ts b/src/type/content-id.ts index c1455d736..54450fa3e 100644 --- a/src/type/content-id.ts +++ b/src/type/content-id.ts @@ -5,4 +5,5 @@ export type ContentId = | "general" | "contacts" | "share" - | "email"; + | "email" + | "telegram";