-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d4a2de
commit 7061a3b
Showing
6 changed files
with
147 additions
and
41 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"clientId": "dinguvrbesopqvisruwh", | ||
"clientSecret": "TwLmIxNSKuZW84nUkCmUWO4fs3Ws8I-CSly3Fo7l00fcnOz899D2Su2AEe8u5Vri" | ||
"clientId": "ding2kdwyyilaknq8zj5", | ||
"clientSecret": "vlDWox885jMZQLm5cQ6lBTtdjqQXEfK-PK5dIL29tPECYdAE0i1A_7wum76BLxzO" | ||
} |
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 |
---|---|---|
@@ -1,41 +1,81 @@ | ||
import {DWClient, DWClientDownStream, EventAck, RobotMessage, TOPIC_ROBOT} from '../src/index.js'; | ||
import axios from 'axios'; | ||
import config from './config.json' assert {type: 'json'}; | ||
import { | ||
DWClient, | ||
DWClientDownStream, | ||
EventAck, | ||
RobotMessage, | ||
TOPIC_ROBOT, | ||
TOPIC_AI_GRAPH_API, | ||
} from "../src/index.js"; | ||
import axios from "axios"; | ||
import config from "./config.json" assert { type: "json" }; | ||
|
||
console.log("开始启动"); | ||
const client = new DWClient({ | ||
clientId: config.clientId, | ||
clientSecret: config.clientSecret, | ||
debug: false | ||
debug: true, | ||
}); | ||
client.registerCallbackListener(TOPIC_ROBOT, async (res) => { | ||
// 注册机器人回调事件 | ||
console.log("收到消息"); | ||
// const {messageId} = res.headers; | ||
const { text, senderStaffId, sessionWebhook } = JSON.parse(res.data) as RobotMessage; | ||
const body = { | ||
at: { | ||
atUserIds: [senderStaffId], | ||
isAtAll: false, | ||
}, | ||
text: { | ||
content: 'nodejs-getting-started say : 收到,' + text?.content || '钉钉,让进步发生', | ||
}, | ||
msgtype: 'text', | ||
}; | ||
// 注册机器人回调事件 | ||
console.log("收到消息"); | ||
debugger; | ||
// const {messageId} = res.headers; | ||
const { text, senderStaffId, sessionWebhook } = JSON.parse( | ||
res.data | ||
) as RobotMessage; | ||
const body = { | ||
at: { | ||
atUserIds: [senderStaffId], | ||
isAtAll: false, | ||
}, | ||
text: { | ||
content: | ||
"nodejs-getting-started say : 收到," + text?.content || | ||
"钉钉,让进步发生", | ||
}, | ||
msgtype: "text", | ||
}; | ||
|
||
const result = await axios({ | ||
url: sessionWebhook, | ||
method: 'POST', | ||
responseType: 'json', | ||
data: body, | ||
headers: { | ||
'x-acs-dingtalk-access-token': client.getConfig().access_token, | ||
}, | ||
}); | ||
const result = await axios({ | ||
url: sessionWebhook, | ||
method: "POST", | ||
responseType: "json", | ||
data: body, | ||
headers: { | ||
"x-acs-dingtalk-access-token": client.getConfig().access_token, | ||
}, | ||
}); | ||
|
||
return result.data; | ||
}) | ||
return result.data; | ||
}); | ||
client | ||
.registerCallbackListener( | ||
TOPIC_AI_GRAPH_API, | ||
async (res: DWClientDownStream) => { | ||
// 注册AI插件回调事件 | ||
console.log("收到ai消息"); | ||
const { messageId } = res.headers; | ||
|
||
// 添加业务逻辑 | ||
console.log(res); | ||
console.log(JSON.parse(res.data)); | ||
|
||
// 通过Stream返回数据 | ||
client.sendGraphAPIResponse(messageId, { | ||
response: { | ||
statusLine: { | ||
code: 200, | ||
reasonPhrase: "OK", | ||
}, | ||
headers: {}, | ||
body: JSON.stringify({ | ||
text: "你好", | ||
}), | ||
}, | ||
}); | ||
} | ||
) | ||
.registerAllEventListener((message: DWClientDownStream) => { | ||
return {status: EventAck.SUCCESS} | ||
return { status: EventAck.SUCCESS }; | ||
}) | ||
.connect(); |
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
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