feat(notifications): added telegram thread id's (#1145)
* feat(notifications): added telegram thread id's * undid unwanted formatting * chore: remove manual translations * style: conformed formatting * fix: add missing migration * fix: corrected erroneous migration
This commit is contained in:
@@ -23,8 +23,13 @@ const messages = defineMessages('components.Settings.Notifications', {
|
||||
chatId: 'Chat ID',
|
||||
chatIdTip:
|
||||
'Start a chat with your bot, add <GetIdBotLink>@get_id_bot</GetIdBotLink>, and issue the <code>/my_id</code> command',
|
||||
messageThreadId: 'Thread/Topic ID',
|
||||
messageThreadIdTip:
|
||||
"If your group-chat has topics enabled, you can specify a thread/topic's ID here",
|
||||
validationBotAPIRequired: 'You must provide a bot authorization token',
|
||||
validationChatIdRequired: 'You must provide a valid chat ID',
|
||||
validationMessageThreadId:
|
||||
'The thread/topic ID must be a positive whole number',
|
||||
telegramsettingssaved: 'Telegram notification settings saved successfully!',
|
||||
telegramsettingsfailed: 'Telegram notification settings failed to save.',
|
||||
toastTelegramTestSending: 'Sending Telegram test notification…',
|
||||
@@ -64,6 +69,15 @@ const NotificationsTelegram = () => {
|
||||
/^-?\d+$/,
|
||||
intl.formatMessage(messages.validationChatIdRequired)
|
||||
),
|
||||
messageThreadId: Yup.string()
|
||||
.when(['types'], {
|
||||
is: (enabled: boolean, types: number) => enabled && !!types,
|
||||
then: Yup.string()
|
||||
.nullable()
|
||||
.required(intl.formatMessage(messages.validationMessageThreadId)),
|
||||
otherwise: Yup.string().nullable(),
|
||||
})
|
||||
.matches(/^\d+$/, intl.formatMessage(messages.validationMessageThreadId)),
|
||||
});
|
||||
|
||||
if (!data && !error) {
|
||||
@@ -78,6 +92,7 @@ const NotificationsTelegram = () => {
|
||||
botUsername: data?.options.botUsername,
|
||||
botAPI: data?.options.botAPI,
|
||||
chatId: data?.options.chatId,
|
||||
messageThreadId: data?.options.messageThreadId,
|
||||
sendSilently: data?.options.sendSilently,
|
||||
}}
|
||||
validationSchema={NotificationsTelegramSchema}
|
||||
@@ -94,6 +109,7 @@ const NotificationsTelegram = () => {
|
||||
options: {
|
||||
botAPI: values.botAPI,
|
||||
chatId: values.chatId,
|
||||
messageThreadId: values.messageThreadId,
|
||||
sendSilently: values.sendSilently,
|
||||
botUsername: values.botUsername,
|
||||
},
|
||||
@@ -151,6 +167,7 @@ const NotificationsTelegram = () => {
|
||||
options: {
|
||||
botAPI: values.botAPI,
|
||||
chatId: values.chatId,
|
||||
messageThreadId: values.messageThreadId,
|
||||
sendSilently: values.sendSilently,
|
||||
botUsername: values.botUsername,
|
||||
},
|
||||
@@ -286,6 +303,28 @@ const NotificationsTelegram = () => {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label htmlFor="messageThreadId" className="text-label">
|
||||
{intl.formatMessage(messages.messageThreadId)}
|
||||
<span className="label-tip">
|
||||
{intl.formatMessage(messages.messageThreadIdTip)}
|
||||
</span>
|
||||
</label>
|
||||
<div className="form-input-area">
|
||||
<div className="form-input-field">
|
||||
<Field
|
||||
id="messageThreadId"
|
||||
name="messageThreadId"
|
||||
type="text"
|
||||
/>
|
||||
</div>
|
||||
{errors.messageThreadId &&
|
||||
touched.messageThreadId &&
|
||||
typeof errors.messageThreadId === 'string' && (
|
||||
<div className="error">{errors.messageThreadId}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label htmlFor="sendSilently" className="checkbox-label">
|
||||
<span>{intl.formatMessage(messages.sendSilently)}</span>
|
||||
|
||||
@@ -21,9 +21,14 @@ const messages = defineMessages(
|
||||
telegramChatId: 'Chat ID',
|
||||
telegramChatIdTipLong:
|
||||
'<TelegramBotLink>Start a chat</TelegramBotLink>, add <GetIdBotLink>@get_id_bot</GetIdBotLink>, and issue the <code>/my_id</code> command',
|
||||
telegramMessageThreadId: 'Thread/Topic ID',
|
||||
telegramMessageThreadIdTip:
|
||||
"If your group-chat has topics enabled, you can specify a thread/topic's ID here",
|
||||
sendSilently: 'Send Silently',
|
||||
sendSilentlyDescription: 'Send notifications with no sound',
|
||||
validationTelegramChatId: 'You must provide a valid chat ID',
|
||||
validationTelegramMessageThreadId:
|
||||
'The thread/topic ID must be a positive whole number',
|
||||
}
|
||||
);
|
||||
|
||||
@@ -53,6 +58,20 @@ const UserTelegramSettings = () => {
|
||||
/^-?\d+$/,
|
||||
intl.formatMessage(messages.validationTelegramChatId)
|
||||
),
|
||||
telegramMessageThreadId: Yup.string()
|
||||
.when(['types'], {
|
||||
is: (enabled: boolean, types: number) => enabled && !!types,
|
||||
then: Yup.string()
|
||||
.nullable()
|
||||
.required(
|
||||
intl.formatMessage(messages.validationTelegramMessageThreadId)
|
||||
),
|
||||
otherwise: Yup.string().nullable(),
|
||||
})
|
||||
.matches(
|
||||
/^\d+$/,
|
||||
intl.formatMessage(messages.validationTelegramMessageThreadId)
|
||||
),
|
||||
});
|
||||
|
||||
if (!data && !error) {
|
||||
@@ -63,6 +82,7 @@ const UserTelegramSettings = () => {
|
||||
<Formik
|
||||
initialValues={{
|
||||
telegramChatId: data?.telegramChatId,
|
||||
telegramMessageThreadId: data?.telegramMessageThreadId,
|
||||
telegramSendSilently: data?.telegramSendSilently,
|
||||
types: data?.notificationTypes.telegram ?? 0,
|
||||
}}
|
||||
@@ -84,6 +104,7 @@ const UserTelegramSettings = () => {
|
||||
pushoverApplicationToken: data?.pushoverApplicationToken,
|
||||
pushoverUserKey: data?.pushoverUserKey,
|
||||
telegramChatId: values.telegramChatId,
|
||||
telegramMessageThreadId: values.telegramMessageThreadId,
|
||||
telegramSendSilently: values.telegramSendSilently,
|
||||
notificationTypes: {
|
||||
telegram: values.types,
|
||||
@@ -162,6 +183,30 @@ const UserTelegramSettings = () => {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label htmlFor="telegramMessageThreadId" className="text-label">
|
||||
{intl.formatMessage(messages.telegramMessageThreadId)}
|
||||
<span className="label-tip">
|
||||
{intl.formatMessage(messages.telegramMessageThreadIdTip)}
|
||||
</span>
|
||||
</label>
|
||||
<div className="form-input-area">
|
||||
<div className="form-input-field">
|
||||
<Field
|
||||
id="telegramMessageThreadId"
|
||||
name="telegramMessageThreadId"
|
||||
type="text"
|
||||
/>
|
||||
</div>
|
||||
{errors.telegramMessageThreadId &&
|
||||
touched.telegramMessageThreadId &&
|
||||
typeof errors.telegramMessageThreadId === 'string' && (
|
||||
<div className="error">
|
||||
{errors.telegramMessageThreadId}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label htmlFor="telegramSendSilently" className="checkbox-label">
|
||||
{intl.formatMessage(messages.sendSilently)}
|
||||
|
||||
Reference in New Issue
Block a user