demo SSE READ SSE README.md
sse.mp4
demo.mp4
import "github.com/isxuelinme/poe_unofficial_api/core"
go mod tidy
function getChatId() {
let channel = localStorage.getItem("poe-tchannel-channel")
let paramsForGetChatId = window.__NEXT_DATA__.buildId
let fetchUrl = "https://poe.com/_next/data/" + paramsForGetChatId + "/sage.json?handle=sage"
fetch(fetchUrl)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not okay');
}
return response.text();
})
.then(data => {
jsonData = JSON.parse(data)
console.log("POE_CHANNEL = ", channel)
console.log("POE_CHAT_ID = ", jsonData.pageProps.payload.chatOfBotDisplayName.chatId)
})
.catch(error => {
console.error('Error fetching data:', error);
});
}(getChatId())
Copy the value of POE_CHANNEL and POE_CHAT_ID after running the above code. The output will look like this:
POE_CHANNEL = poe-chan51-8888-hhmp2zuksgonnzdwnitj
POE_CHAT_ID = 550223
POE_COOKIE = <your cookie>
POE_CHANNEL = <your channel>
POE_CHAT_ID = <your chat_id>
RUN_MODE = SSE
BACKEND_PORT = <backend port if not set default is 6000>
package main
import "github.com/isxuelinme/poe_unofficial_api/core"
func main() {
core.SetLogMode(core.LOG_ERROR)
MutLtiUser := core.NewMutLtiUserGpt(core.GptTypePoeUnofficial)
ask := &core.AskRequest{
UserId: 1, //your local user id
Question: "hi~ bro",
CallbackFuncName: "", //useless. Like JSONP or event name
// when message Coming from GPT, it will call this function
AskResponseCallBack: func(askRequest *core.AskRequest, response *core.CallbackMessageResponse) {
fmt.Printf("\r answer: %s", message.Data.Text)
},
}
//ask question
MutLtiUser.Talk(ask)
select {}
}
It's easy to use,However, you can use AskResponseCallBack to implement websocket or more protocol by yourself. learn more READ SSE IMPLEMENT
ask := &core.AskRequest{
UserId: 1,
Question: "hi~ bro",
CallbackFuncName: "",
AskResponseCallBack: func (askRequest *core.AskRequest, response *core.CallbackMessageResponse) {
<your business logiical code>
},
}
It has implemented multi-user, but it is not friendly to business and especially noobs, just for dev/test. So you have to read the code by yourself.
end.