Skip to content

Commit

Permalink
feat(nuxt3): slack qa command
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu committed Jun 25, 2023
1 parent 78d0f6f commit 9913aea
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/core/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ describe('utils', () => {
expect(countAfter).toMatchSnapshot()
})
test('Cryption', async () => {
const crytion = new Cryption(32456, 46981)
const C1 = 32456
const C2 = 46981
const crytion = new Cryption(C1, C2)
const config = {
app: {
telegram: {
Expand Down
2 changes: 1 addition & 1 deletion server/nuxt3/server/api/slack/[appid]/adduser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default eventHandler(async (event) => {
publicKey.forEach((key) => {
const _key = key as keyof ServerConfig<OutUserConfig>
if (!_userConfig[_key])
_userConfig[key] = thisConfig[_key].config
_userConfig[key] = thisConfig[_key]
})
await setUserConfig('slack', appId, userId, _userConfig)
}
Expand Down
18 changes: 18 additions & 0 deletions server/nuxt3/server/api/slack/[appid]/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cryption } from '../../../../constants/index'
import type { KVConfig, ServerConfig } from '../../../../composables/config'
import type { UserConfig } from '../../../utils'

export default eventHandler(async (event) => {
const raw = await readBody(event)
Expand Down Expand Up @@ -47,4 +48,21 @@ export default eventHandler(async (event) => {
],
}
}
else if (raw.command === '/qa') {
const userConfig = await getUserConfig('slack', raw.api_app_id, raw.user_id)
const question = raw.text
if (userConfig)
MakeQAChain(question, { USER_CONFIG: userConfig as UserConfig }, 'slack', raw.api_app_id, raw.user_id)
return {
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Question: ${question}`,
},
},
],
}
}
})
4 changes: 2 additions & 2 deletions server/nuxt3/server/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function getUserConfig(app: AppName, appId: string, userId: string)
}
}

export async function MakeQAChain(question: string, context: Context, appName: string, botId: string, userId: string) {
export async function MakeQAChain(question: string, context: { USER_CONFIG: UserConfig }, appName: string, botId: string, userId: string) {
const config = context.USER_CONFIG as UserConfig

const llm = new (llmInfo[config.llm.select as TLLM])(config.llm.config)
Expand Down Expand Up @@ -142,7 +142,7 @@ export async function MakeQAChain(question: string, context: Context, appName: s

try {
if (appName === 'telegram')
return (await sendMessageToTelegramWithContext(context)(message))
return (await sendMessageToTelegramWithContext(context as Context)(message))
else if (appName === 'slack')
return (await sendMessageToSlackBot(config.app.config.webhook, message))
}
Expand Down

1 comment on commit 9913aea

@vercel
Copy link

@vercel vercel bot commented on 9913aea Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

star-nexus – ./

star-nexus.vercel.app
star-nexus-larchliu.vercel.app
star-nexus-git-main-larchliu.vercel.app

Please sign in to comment.