Skip to content

Commit

Permalink
fix: Bing Chat UnauthorizedRequest error
Browse files Browse the repository at this point in the history
fix #518
  • Loading branch information
sunner committed Aug 26, 2023
1 parent c522fc5 commit 57fdcf1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/bots/microsoft/BingChatBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@ export default class BingChatBot extends Bot {
const headers = {
"x-ms-client-request-id": uuidv4(),
"x-ms-useragent":
"azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.0 OS/MacIntel",
"azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/macOS",
};
let conversation = null;

const response = await axios.get(
"https://www.bing.com/turing/conversation/create",
{ headers },
);
if (response.data && response.data.result.value == "Success") {
console.log(response);
if (
response.status == 200 &&
response.data &&
response.data.result.value == "Success"
) {
// Save the conversation context
conversation = {
clientId: response.data.clientId,
conversationId: response.data.conversationId,
conversationSignature: response.data.conversationSignature,
conversationSignature:
response.headers["x-sydney-conversationsignature"],
secAccessToken:
response.headers["x-sydney-encryptedconversationsignature"],
invocationId: 0,
};
} else {
Expand Down Expand Up @@ -111,7 +119,6 @@ export default class BingChatBot extends Bot {
},
tone: this.constructor._tone,
requestId: uuid,
conversationSignature: context.conversationSignature,
participant: { id: context.clientId },
conversationId: context.conversationId,
},
Expand All @@ -128,7 +135,9 @@ export default class BingChatBot extends Bot {
try {
const seperator = String.fromCharCode(30);
const wsp = new WebSocketAsPromised(
"wss://sydney.bing.com/sydney/ChatHub",
`wss://sydney.bing.com/sydney/ChatHub?sec_access_token=${encodeURIComponent(
context.secAccessToken,
)}`,
{
packMessage: (data) => {
return JSON.stringify(data) + seperator;
Expand Down

0 comments on commit 57fdcf1

Please sign in to comment.