This repository was archived by the owner on Nov 5, 2025. It is now read-only.
[NEW] Add ON_PRE_SETTING_UPDATE hook to apps#417
Merged
Conversation
Contributor
Author
import {
IAppAccessors, IConfigurationExtend, IConfigurationModify, IEnvironmentRead, IHttp, ILogger, IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { InvalidSettingException } from '@rocket.chat/apps-engine/definition/exceptions';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import { ISetting, SettingType } from '@rocket.chat/apps-engine/definition/settings';
import { ISettingUpdateContext } from '../../apps-engine/definition/settings/ISettingUpdateContext';
export class AppsSettings extends App {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
public async initialize(configurationExtend: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
configurationExtend.settings.provideSetting({
id: 'Telegram',
public: true,
type: SettingType.SELECT,
packageValue: 'none',
value: 'none',
values: [
{
key: 'none',
i18nLabel: 'none',
},
{
key: 'name',
i18nLabel: 'name',
},
{
key: 'username',
i18nLabel: 'username',
},
{
key: 'nickname',
i18nLabel: 'nickname',
},
],
i18nLabel: 'telegram_agents_display_name',
i18nDescription: 'telegram_agents_display_name_description',
required: true,
});
}
public async onPreSettingUpdate(context: ISettingUpdateContext, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<ISetting> {
const { oldSetting, newSetting: setting } = context;
console.log({ oldSetting: oldSetting.value, newSetting: setting.value });
switch (setting.id) {
case 'Telegram': {
switch (setting.value) {
case 'none':
throw new InvalidSettingException('The value of the setting Telegram cannot be `none`');
}
break;
}
}
return setting;
}
}The app for testing: screeshots: |
Codecov Report
@@ Coverage Diff @@
## alpha #417 +/- ##
==========================================
+ Coverage 48.67% 48.72% +0.04%
==========================================
Files 103 103
Lines 3244 3247 +3
Branches 476 478 +2
==========================================
+ Hits 1579 1582 +3
Misses 1665 1665
Continue to review full report at Codecov.
|
d-gubert
suggested changes
May 26, 2021
d-gubert
suggested changes
May 26, 2021
d-gubert
suggested changes
May 26, 2021
d-gubert
approved these changes
May 31, 2021
This was referenced Jun 1, 2021
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What? ⛵
This PR introduces a new
onPreSettingUpdatehook into apps. In this way, app developers can validate new setting update before it takes effects.Why? 🤔
RFC 37
Links 🌎
PS 👀