-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.tsx
85 lines (67 loc) · 2.28 KB
/
options.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { useStorage } from "@plasmohq/storage/hook";
import { events, models } from "configs";
function OptionsIndex() {
const [event, setEvent] = useStorage<string>("event", events[0])
const [openaiKey, setOpenaiKey] = useStorage<string>("openaiKey", "")
const [openaiModel, setOpenaiModel] = useStorage<string>("openaiModel", models[0])
const [tgBotToken, setTgBotToken] = useStorage<string>("tgBotToken", "")
const [tgChatId, setTgChatId] = useStorage<string>("tgChatId", "")
const autoSetTgChatId = () => {
fetch(`https://api.telegram.org/bot${tgBotToken}/getUpdates?allowed_updates=["message"]&timeout=60`)
.then((response) => response.json())
.then((data) => {
const updates = data.result;
if (updates.length > 0 && updates[0]?.message?.chat?.id) {
setTgChatId(updates[0]?.message?.chat?.id);
}
})
};
return (
<div>
<h1>
Welcome to Google Form GPT Assistent!
</h1>
<h2>Settings:</h2>
<h3>Event on answer</h3>
<select value={event} onChange={e => setEvent(e.target.value)}>
{events.map(m => <option key={m} value={m}>{m}</option>)}
</select>
<br/>
<br/>
<h2>OpenAI settings:</h2>
<h3>API key</h3>
<input
style={{ width: "400px" }}
onChange={(e) => setOpenaiKey(e.target.value)}
value={openaiKey}
/>
<br/>
<h3>Model</h3>
<select value={openaiModel} onChange={e => setOpenaiModel(e.target.value)}>
{models.map(m => <option key={m} value={m}>{m}</option>)}
</select>
<br/>
<br/>
<h2>Telegram settings:</h2>
<h3>Token</h3>
<input
style={{ width: "400px" }}
onChange={(e) => setTgBotToken(e.target.value)}
value={tgBotToken}
/>
<br/>
<h3>Chat ID</h3>
<input
style={{ width: "100px" }}
onChange={(e) => setTgChatId(e.target.value)}
value={tgChatId}
/>
{!tgChatId && (
<span onClick={autoSetTgChatId}>
To automatically set up the Chat ID, please click here. In case you are using a group chat, mention the bot. If you are using a private chat, just send any text message.
</span>
)}
</div>
)
}
export default OptionsIndex