forked from sytpb/chatgpt-wework-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
156 additions
and
17 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict" | ||
|
||
const types = {text: "TEXT", image: "IMAGE", voice: "AUDIO"}; | ||
|
||
export default class Chat { | ||
|
||
constructor(name) { | ||
this.#type = types[name]; | ||
} | ||
|
||
type() { | ||
return this.#type; | ||
} | ||
|
||
process(req, res) { | ||
|
||
} | ||
|
||
} |
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,31 @@ | ||
"use strict" | ||
|
||
|
||
import Chat from "./chat.js"; | ||
import debug from "../comm/debug.js"; | ||
import getAIChat from "../openai.js"; | ||
|
||
export default class TextChat extends Chat{ | ||
|
||
constructor(name) { | ||
super(name); | ||
} | ||
|
||
process(xml) { | ||
|
||
const question = xml.content; | ||
|
||
getAIChat(question).then(result => { | ||
const content = result?.data?.choices[0]?.message?.content; | ||
if(!!content) { | ||
const answer = content; | ||
|
||
debug.log(answer); | ||
console.log(answer); | ||
//message.sendMsg(answer, toUser); | ||
} | ||
|
||
}) | ||
} | ||
|
||
} |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
import debug from "../comm/debug.js"; | ||
import Message from "../comm/message.js"; | ||
|
||
export default class Conversation { | ||
|
||
constructor() { | ||
} | ||
|
||
urlconfig(req, res) { | ||
const message = new Message(); | ||
message.urlSetting(req, res); | ||
} | ||
|
||
async process(body, res) { | ||
|
||
let chat = null; | ||
const data = body; | ||
const message = new Message(); | ||
const xml = await message.decode(data); | ||
const msgType = xml.MsgType; | ||
debug.log(msgType); | ||
|
||
if(msgType === "text") { | ||
chat = new textChat(msgType,xml); | ||
} | ||
else if (msgType === "image") { | ||
chat = new imageChat(msgType,xml); | ||
} | ||
else if (msgType === "voice") { | ||
chat = new audioChat(msgType,xml); | ||
} | ||
|
||
if(!!chat) { | ||
const answer = chat.process(xml); | ||
|
||
//comm.response(answer,res) | ||
return; | ||
} | ||
|
||
//debug.log("Not support msgtype []"); | ||
} | ||
|
||
|
||
} |
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,19 @@ | ||
|
||
import Conversation from "../handler/conversation.js"; | ||
|
||
import express from "express"; | ||
const router = express.Router(); | ||
|
||
router.use('/', function(req, res, next) { | ||
let method = req.method; | ||
if(method == 'GET') { | ||
} | ||
else if(method == 'POST') { | ||
console.log(`------------------------ROUTER MSG [CONVERSATION]-------------------------`); | ||
const conversation = new Conversation(); | ||
conversation.process(req.body,'',res); | ||
} | ||
}); | ||
|
||
export default router; | ||
|
File renamed without changes.