Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Thank You larainfo-->
- {% load static %}
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title> Chatbot Eva </title>
- <link src="{% static 'css/style.css' %}">
- <script src="https://cdn.tailwindcss.com"></script>
- </head>
- <body>
- {% if request.user.is_authenticated %}
- {% csrf_token %}
- <div class="container mx-auto">
- <div class="max-w-2xl border rounded">
- <div>
- <div class="w-full">
- <div class="relative flex items-center p-3 border-b border-gray-300">
- <img class="object-cover w-10 h-10 rounded-full"
- src="{% static 'img/evabot.ico' %}" alt="username" />
- <span class="block ml-2 font-bold text-gray-600">Eva</span>
- <span class="absolute w-3 h-3 bg-green-600 rounded-full left-10 top-3">
- </span>
- </div>
- <div class="relative w-full p-6 overflow-y-auto h-auto" id="chat" class="chat">
- <div id="chat-log" class="flex flex-col overflow-scroll h-[470px]">
- <!--text-area-->
- </div>
- <div class="relative flex items-center justify-between w-full p-3 border-t border-gray-300">
- <input id="chat-message-input" autofocus="true" type="text" placeholder="Message"
- class="block w-full py-2 pl-4 mx-3 bg-gray-100 rounded-full outline-none focus:text-gray-700"
- name="message" autocomplete="off" autofocus="true" required />
- <span class="px-2 py-2">
- <button>
- <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-gray-500" fill="none" viewBox="0 0 24 24"
- stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
- d="M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z" />
- </svg>
- </button>
- </span>
- <span class="px-2 py-2">
- <input id="chat-message-submit" type="button" value="Send">
- <svg class="w-5 h-5 text-gray-500 origin-center transform rotate-90" xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 20 20" fill="currentColor">
- <path
- d="M10.894 2.553a1 1 0 00-1.788 0l-7 14a1 1 0 001.169 1.409l5-1.429A1 1 0 009 15.571V11a1 1 0 112 0v4.571a1 1 0 00.725.962l5 1.428a1 1 0 001.17-1.408l-7-14z" />
- </svg>
- </input>
- </div>
- </span>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
- <!-- Your custom script here -->
- {{ username|json_script:"user-name" }}
- <script>
- const roomName = JSON.parse(document.getElementById('user-name').textContent);
- const chatSocket = new WebSocket(
- 'ws://'
- + window.location.host
- + '/ws/'
- + roomName
- + '/'
- );
- chatSocket.onmessage = function(e) {
- const data = JSON.parse(e.data);
- document.querySelector('#chat-log').value += (data.message + '\n');
- };
- chatSocket.onclose = function(e) {
- console.error('Chat socket closed unexpectedly');
- };
- document.querySelector('#chat-message-input').focus();
- document.querySelector('#chat-message-input').onkeyup = function(e) {
- if (e.keyCode === 13) { // enter, return
- document.querySelector('#chat-message-submit').click();
- }
- };
- document.querySelector('#chat-message-submit').onclick = function(e) {
- const messageInputDom = document.querySelector('#chat-message-input');
- const message = messageInputDom.value;
- chatSocket.send(JSON.stringify({
- 'message': message
- }));
- messageInputDom.value = '';
- };
- </script>
- {% else %}
- <div class="mt-5 text-sm font-display font-semibold text-gray-700 text-center">
- Don't have an account? <a class="cursor-pointer text-indigo-600 hover:text-indigo-800" href="{% url 'signup' %}">Sign up</a>
- </div>
- <br/>
- <div class="mt-5 text-sm font-display font-semibold text-gray-700 text-center">
- Already have an account? <a class="cursor-pointer text-indigo-600 hover:text-indigo-800" href="{% url 'signin' %}">Sign in</a>
- </div>
- {% endif %}
- </body>
- </html>
Add Comment
Please, Sign In to add comment