Add basic chat box when getting a warning

This commit is contained in:
Ajay Ramachandran
2021-07-29 18:16:44 -04:00
parent 1656fae2d4
commit 1a855a6993
6 changed files with 63 additions and 7 deletions

30
src/js-components/chat.ts Normal file
View File

@@ -0,0 +1,30 @@
import Config from "../config";
import Utils from "../utils";
const utils = new Utils();
export interface ChatConfig {
displayName: string,
composerInitialValue?: string,
customDescription?: string
}
export function openChat(config: ChatConfig): void {
const chat = document.createElement("iframe");
chat.src = "https://chat.sponsor.ajay.app/#" + utils.objectToURI("", config, false);
chat.classList.add("chatNotice");
chat.style.zIndex = "2000";
console.log(utils.objectToURI("", config, false))
const referenceNode = utils.findReferenceNode();
referenceNode.prepend(chat);
}
export async function openWarningChat(warningMessage: string): Promise<void> {
openChat({
displayName: await utils.getHash(Config.config.userID),
composerInitialValue: `I got a warning and want to know what I need to do to improve. ` +
`Warning reason: ${warningMessage.match(/Warning reason: '(.+)'/)[1]}`,
customDescription: chrome.i18n.getMessage("warningChatInfo")
});
}