mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
feat: add support for Claude and Poe(WIP)
This commit is contained in:
parent
a3a16bc5ff
commit
7ef6051da8
38 changed files with 882 additions and 19 deletions
59
utils/slack/slackClient.js
Normal file
59
utils/slack/slackClient.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import { Config } from '../config.js'
|
||||
import slack from '@slack/bolt'
|
||||
let proxy
|
||||
if (Config.proxy) {
|
||||
try {
|
||||
proxy = (await import('https-proxy-agent')).default
|
||||
} catch (e) {
|
||||
console.warn('未安装https-proxy-agent,请在插件目录下执行pnpm add https-proxy-agent')
|
||||
}
|
||||
}
|
||||
export class SlackClaudeClient {
|
||||
constructor (props) {
|
||||
this.config = props
|
||||
if (Config.slackSigningSecret && Config.slackBotUserToken && Config.slackUserToken) {
|
||||
let option = {
|
||||
signingSecret: Config.slackSigningSecret,
|
||||
token: Config.slackBotUserToken,
|
||||
// socketMode: true,
|
||||
appToken: Config.slackUserToken
|
||||
// port: 45912
|
||||
}
|
||||
if (Config.proxy) {
|
||||
option.agent = proxy(Config.proxy)
|
||||
}
|
||||
this.app = new slack.App(option)
|
||||
} else {
|
||||
throw new Error('未配置Slack信息')
|
||||
}
|
||||
}
|
||||
|
||||
async sendMessage (prompt) {
|
||||
let sendResponse = await this.app.client.chat.postMessage({
|
||||
as_user: true,
|
||||
text: `${prompt}`,
|
||||
token: this.config.slackUserToken,
|
||||
channel: this.config.slackChannelId
|
||||
})
|
||||
let ts = sendResponse.ts
|
||||
let response = '_Typing…_'
|
||||
while (response.trim().endsWith('_Typing…_')) {
|
||||
let replies = await this.app.client.conversations.history({
|
||||
token: this.config.slackUserToken,
|
||||
channel: this.config.slackChannelId,
|
||||
limit: 1,
|
||||
oldest: ts
|
||||
})
|
||||
if (replies.messages.length > 0) {
|
||||
response = replies.messages[0].text
|
||||
if (Config.debug) {
|
||||
let text = response.replace('_Typing…_', '')
|
||||
if (text) {
|
||||
logger.info(response.replace('_Typing…_', ''))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue