-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bot ctrl, handle noun list (#70)
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
metadata: | ||
kind: bot-controller | ||
name: default-bot | ||
data: | ||
filters: [] | ||
transforms: | ||
- metadata: | ||
kind: template-transform | ||
name: default-bot-template | ||
data: | ||
templates: | ||
body: >- | ||
{{#each data}} | ||
{{key}}: {{noun}} | ||
{{/each}} | ||
- metadata: | ||
kind: flatten-transform | ||
name: default-bot-flatten | ||
data: | ||
deep: false | ||
join: '' | ||
keys: [$.data.body] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { endsWith } from 'lodash'; | ||
|
||
import { CheckRBAC, Controller, ControllerData, Handler } from 'src/controller'; | ||
import { BaseController, BaseControllerOptions } from 'src/controller/BaseController'; | ||
import { Command, CommandVerb } from 'src/entity/Command'; | ||
import { Context } from 'src/entity/Context'; | ||
|
||
export const NOUN_NOUN = 'bot-noun'; | ||
|
||
export type BotControllerData = ControllerData; | ||
|
||
export class BotController extends BaseController<BotControllerData> implements Controller { | ||
constructor(options: BaseControllerOptions<BotControllerData>) { | ||
super(options, 'isolex#/definitions/service-controller-bot', [NOUN_NOUN]); | ||
} | ||
|
||
@Handler(NOUN_NOUN, CommandVerb.List) | ||
@CheckRBAC() | ||
public async getNouns(cmd: Command, ctx: Context): Promise<void> { | ||
const nouns = []; | ||
for (const [key, svc] of this.services.listServices()) { | ||
if (endsWith(svc.kind, '-controller')) { | ||
const svcNouns = Reflect.get(svc, 'nouns'); | ||
if (svcNouns instanceof Set) { | ||
for (const noun of svcNouns) { | ||
nouns.push({ | ||
key, | ||
noun, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return this.transformJSON(cmd, nouns); | ||
} | ||
} |
This file contains 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
This file contains 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