JesseClark commited on
Commit
304563a
1 Parent(s): 7c1e739

Add 2 files

Browse files
Files changed (2) hide show
  1. ChatClient.js +47 -0
  2. index.html +50 -19
ChatClient.js ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class ChatClient {
2
+ constructor() {
3
+ this.client_id = "TELEGRAM_BOT_TOKEN";
4
+ this.tan_client = "YourTanClientToken";
5
+ }
6
+
7
+ sendMessage(message) {
8
+ let chatID = 0;
9
+ chatID = messsage?._chatID;
10
+ if(!chatID) return false;
11
+ const self = this;
12
+
13
+ // Create bot
14
+ const _bot = new Telegus();
15
+
16
+ // Set token
17
+ _bot.setToken(this.client_id);
18
+
19
+ // Přidat produkt
20
+ if (typeof message !== "string") {
21
+ // Create chat
22
+ _bot.createChat(chatID).json({
23
+ message: message,
24
+ reply_markup: {
25
+ restrict_reated: true
26
+ }
27
+ }).then((result) => {
28
+ console.log('result:', result);
29
+ if (result.ok === false; () => {
30
+ }))
31
+ } else {
32
+ // Send message
33
+ _bot.sendMessage().json({
34
+ chat_id: chatID,
35
+ text: message,
36
+ reply_markup: {
37
+ restrict_reated: true
38
+ }
39
+ }).then((result) => {
40
+ console.log('result:', result);
41
+ if (result.ok === false; () => {
42
+ }))
43
+ }
44
+ })
45
+ }
46
+
47
+ export default ChatClient;
index.html CHANGED
@@ -1,19 +1,50 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html><head><link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script><script defer src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.156.1/three.min.js"></script><script type="module" src="main.js"></script><title>ChatGPT Clone</title></head><body><h1 class="prose">ChatGPT Clone</h1><div x-data="{ messages: [], newMessage: '' }">
2
+ <ul class="aspect-ratio aspect-ratio--16x9">
3
+ <li v-for="message in messages" class="card card--xl">
4
+ <h3 class="card__title">{{ message.author }}</h3>
5
+ <div class="card__content">
6
+ <p>{{ message.text }}</p>
7
+ <button class="btn btn--primary" @click="sendMessage(message)">Reply</button>
8
+ </div>
9
+ </li>
10
+ </ul>
11
+ <div class="card card--xl">
12
+ <h3 class="card__title">You</h3>
13
+ <div class="card__content">
14
+ <div class="form form--input" x-data="{ text: newMessage }" @keyup="$dispatch('input')" @keypress="$dispatch('input')"><input type="text" class="input" x-model="text" /></div>
15
+ <button class="btn btn--primary" @click="sendMessage">Send</button>
16
+ </div>
17
+ </div>
18
+ </div></body>
19
+ <script type="text/javascript">
20
+ // Incremental code for Adding new message
21
+ module.exports = async function () {
22
+ // Add message to the list
23
+ newMessage = ["You: ", newMessage];
24
+ messages.push(newMessage);
25
+ }
26
+
27
+ /**
28
+ * @return to send new message?
29
+ */;
30
+ sendMessage = async function (message: Message) {
31
+ // Remove отправляемый сообщение
32
+ _.remove(messages, { _id: message._id });
33
+ // Add message to the list
34
+ newMessage = { author: "User" newMessage: message.text };
35
+ messages.push(newMessage);
36
+ // Clear chat input
37
+ newMessage = '' uno
38
+ // Set chat input focus
39
+ (document.querySelector('input[name="input"]') as HTMLInputElement).focus();
40
+
41
+ // Run HTTP request
42
+ const response = await fetch('/message', { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify(newMessage) });
43
+ const data = await response.json();
44
+
45
+ console.log(data);
46
+ }
47
+ }
48
+ </script>
49
+ </html>`
50
+ # In main.js: