diff --git a/api_webchat/controller.js b/api_webchat/controller.js
index 66df2815..ebfa5a08 100644
--- a/api_webchat/controller.js
+++ b/api_webchat/controller.js
@@ -64,3 +64,13 @@ worker.onmessage = function(event) {
console.error('Unknown event type from worker:', type);
}
};
+
+
+browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
+ console.log(">>>>>>>>>>>>> controller.js onMessage: " + JSON.stringify(message));
+ if (message.command === "chatgpt_send") {
+ //send the received prompt to the chatgpt api
+ messageInput._setMessageInputValue(message.prompt);
+ messageInput._handleNewChatMessage();
+ }
+});
\ No newline at end of file
diff --git a/api_webchat/index.html b/api_webchat/index.html
index 87c15640..cdad673c 100644
--- a/api_webchat/index.html
+++ b/api_webchat/index.html
@@ -13,7 +13,6 @@
-
diff --git a/api_webchat/messageInput.js b/api_webchat/messageInput.js
index 94d95547..db1063fd 100644
--- a/api_webchat/messageInput.js
+++ b/api_webchat/messageInput.js
@@ -135,6 +135,10 @@ class MessageInput extends HTMLElement {
}
this.worker.postMessage({ type: 'chatMessage', message: messageContent });
}
+
+ _setMessageInputValue(msg) {
+ this._messageInputField.value = msg;
+ }
}
customElements.define('message-input', MessageInput);
\ No newline at end of file
diff --git a/mzta-background.js b/mzta-background.js
index bc55bee9..e159b060 100644
--- a/mzta-background.js
+++ b/mzta-background.js
@@ -158,7 +158,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
console.log("[ThunderAI] ChatGPT web interface script started...");
createdWindowID = newWindow.id;
- const createdTab = newWindow.tabs[0];
+ let createdTab = newWindow.tabs[0];
// Wait for tab loaded.
await new Promise(resolve => {
@@ -206,6 +206,15 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
width: prefs.chatgpt_win_width,
height: prefs.chatgpt_win_height
});
+
+ createdWindowID = newWindow.id;
+ let createdTab = newWindow.tabs[0];
+
+ let mailMessage = await browser.messageDisplay.getDisplayedMessage(curr_tabId);
+ let mailMessageId = -1;
+ if(mailMessage) mailMessageId = mailMessage.id;
+
+ browser.tabs.sendMessage(createdTab.id, { command: "chatgpt_send", prompt: promptText, action: action, tabId: curr_tabId, mailMessageId: mailMessageId});
}
}