Update up_gr.html
Browse files- up_gr.html +10 -32
up_gr.html
CHANGED
|
@@ -31,18 +31,6 @@
|
|
| 31 |
border: 1px solid #ccc;
|
| 32 |
border-radius: 5px;
|
| 33 |
}
|
| 34 |
-
.id-container {
|
| 35 |
-
margin-top: 20px;
|
| 36 |
-
}
|
| 37 |
-
.id-container .group-id {
|
| 38 |
-
color: #007BFF;
|
| 39 |
-
text-decoration: none;
|
| 40 |
-
font-size: 16px;
|
| 41 |
-
cursor: pointer;
|
| 42 |
-
}
|
| 43 |
-
.id-container .group-id:hover {
|
| 44 |
-
text-decoration: underline;
|
| 45 |
-
}
|
| 46 |
.create-button {
|
| 47 |
color: white;
|
| 48 |
background-color: #4CAF50;
|
|
@@ -61,36 +49,36 @@
|
|
| 61 |
<body>
|
| 62 |
<h1>Create Group with Members</h1>
|
| 63 |
<div class="input-row">
|
|
|
|
| 64 |
<input type="text" id="groupNameInput" placeholder="Enter group name">
|
| 65 |
</div>
|
| 66 |
<input type="file" id="fileInput" accept=".txt">
|
| 67 |
<button class="create-button" id="createGroupButton">Create Group</button>
|
| 68 |
-
<div class="id-container">
|
| 69 |
-
<span class="group-id" id="groupIdToCopy" onclick="copyToClipboard(this)">Click here to copy the group ID</span>
|
| 70 |
-
</div>
|
| 71 |
|
| 72 |
<script>
|
| 73 |
document.getElementById('createGroupButton').addEventListener('click', async function() {
|
|
|
|
| 74 |
const groupName = document.getElementById('groupNameInput').value;
|
| 75 |
const fileInput = document.getElementById('fileInput');
|
| 76 |
const file = fileInput.files[0];
|
| 77 |
-
if (!groupName || !file) {
|
| 78 |
-
alert('Please enter
|
| 79 |
return;
|
| 80 |
}
|
| 81 |
const reader = new FileReader();
|
| 82 |
reader.onload = async function(event) {
|
| 83 |
const text = event.target.result;
|
| 84 |
-
const
|
| 85 |
const payload = {
|
| 86 |
groupName: groupName,
|
| 87 |
-
|
| 88 |
};
|
| 89 |
try {
|
| 90 |
-
const response = await fetch('https://api.
|
| 91 |
method: 'POST',
|
| 92 |
headers: {
|
| 93 |
-
'Content-Type': 'application/json'
|
|
|
|
| 94 |
},
|
| 95 |
body: JSON.stringify(payload)
|
| 96 |
});
|
|
@@ -98,8 +86,8 @@
|
|
| 98 |
throw new Error(`HTTP error! status: ${response.status}`);
|
| 99 |
}
|
| 100 |
const data = await response.json();
|
| 101 |
-
document.getElementById('groupIdToCopy').innerText = data.groupId;
|
| 102 |
alert('Group created successfully!');
|
|
|
|
| 103 |
} catch (error) {
|
| 104 |
console.error('Error creating group:', error);
|
| 105 |
alert('Error creating group.');
|
|
@@ -107,16 +95,6 @@
|
|
| 107 |
};
|
| 108 |
reader.readAsText(file);
|
| 109 |
});
|
| 110 |
-
|
| 111 |
-
function copyToClipboard(element) {
|
| 112 |
-
const tempInput = document.createElement('input');
|
| 113 |
-
document.body.appendChild(tempInput);
|
| 114 |
-
tempInput.value = element.innerText;
|
| 115 |
-
tempInput.select();
|
| 116 |
-
document.execCommand('copy');
|
| 117 |
-
document.body.removeChild(tempInput);
|
| 118 |
-
alert('Group ID copied to clipboard!');
|
| 119 |
-
}
|
| 120 |
</script>
|
| 121 |
</body>
|
| 122 |
</html>
|
|
|
|
| 31 |
border: 1px solid #ccc;
|
| 32 |
border-radius: 5px;
|
| 33 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
.create-button {
|
| 35 |
color: white;
|
| 36 |
background-color: #4CAF50;
|
|
|
|
| 49 |
<body>
|
| 50 |
<h1>Create Group with Members</h1>
|
| 51 |
<div class="input-row">
|
| 52 |
+
<input type="text" id="apiKeyInput" placeholder="Enter API key">
|
| 53 |
<input type="text" id="groupNameInput" placeholder="Enter group name">
|
| 54 |
</div>
|
| 55 |
<input type="file" id="fileInput" accept=".txt">
|
| 56 |
<button class="create-button" id="createGroupButton">Create Group</button>
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
<script>
|
| 59 |
document.getElementById('createGroupButton').addEventListener('click', async function() {
|
| 60 |
+
const apiKey = document.getElementById('apiKeyInput').value;
|
| 61 |
const groupName = document.getElementById('groupNameInput').value;
|
| 62 |
const fileInput = document.getElementById('fileInput');
|
| 63 |
const file = fileInput.files[0];
|
| 64 |
+
if (!apiKey || !groupName || !file) {
|
| 65 |
+
alert('Please enter an API key, group name, and select a file.');
|
| 66 |
return;
|
| 67 |
}
|
| 68 |
const reader = new FileReader();
|
| 69 |
reader.onload = async function(event) {
|
| 70 |
const text = event.target.result;
|
| 71 |
+
const chatIds = text.split('\n').map(line => line.trim()).filter(line => line);
|
| 72 |
const payload = {
|
| 73 |
groupName: groupName,
|
| 74 |
+
chatIds: chatIds
|
| 75 |
};
|
| 76 |
try {
|
| 77 |
+
const response = await fetch('https://api.green-api.com/waInstance1101952913/createGroup/fb4986a9d9cb40ef9be6c7b08cb9c98b7a3b1dc8c6834b0b92', {
|
| 78 |
method: 'POST',
|
| 79 |
headers: {
|
| 80 |
+
'Content-Type': 'application/json',
|
| 81 |
+
'Authorization': `Bearer ${apiKey}`
|
| 82 |
},
|
| 83 |
body: JSON.stringify(payload)
|
| 84 |
});
|
|
|
|
| 86 |
throw new Error(`HTTP error! status: ${response.status}`);
|
| 87 |
}
|
| 88 |
const data = await response.json();
|
|
|
|
| 89 |
alert('Group created successfully!');
|
| 90 |
+
console.log(data);
|
| 91 |
} catch (error) {
|
| 92 |
console.error('Error creating group:', error);
|
| 93 |
alert('Error creating group.');
|
|
|
|
| 95 |
};
|
| 96 |
reader.readAsText(file);
|
| 97 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
</script>
|
| 99 |
</body>
|
| 100 |
</html>
|