Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack API #401

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions New_APIs/Slack API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Slack Message Sender</title>
</head>
<body>
<header>
<h1>Slack Message Sender</h1>
</header>
<main>
<section>
<form id="message-form">
<input type="text" id="channel" placeholder="Channel Name" required>
<textarea id="message" placeholder="Type your message here..." required></textarea>
<button type="submit">Send Message</button>
</form>
<div id="status"></div>
</section>
</main>
<script src="index.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions New_APIs/Slack API/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
document.getElementById('message-form').addEventListener('submit', async (e) => {
e.preventDefault();

const channel = document.getElementById('channel').value;
const message = document.getElementById('message').value;

try {
const response = await fetch('/send-message', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ channel, message })
});

const data = await response.json();

if (data.success) {
document.getElementById('status').textContent = 'Message sent successfully!';
} else {
document.getElementById('status').textContent = 'Failed to send message.';
}
} catch (error) {
console.error('Error:', error);
document.getElementById('status').textContent = 'An error occurred while sending the message.';
}
});
37 changes: 37 additions & 0 deletions New_APIs/Slack API/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions New_APIs/Slack API/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "slack-message-sender",
"version": "1.0.0",
"description": "A simple app to send messages to Slack channels using the Slack API",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "Your Name",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"node-fetch": "^2.6.1",
"body-parser": "^1.19.0"
}
}

43 changes: 43 additions & 0 deletions New_APIs/Slack API/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const express = require('express');
const fetch = require('node-fetch');
const bodyParser = require('body-parser');

const app = express();
app.use(express.static('public'));
app.use(bodyParser.json());

const SLACK_TOKEN = 'YOUR_SLACK_BOT_TOKEN';

app.post('/send-message', async (req, res) => {
const { channel, message } = req.body;

try {
const response = await fetch('https://slack.com/api/chat.postMessage', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${SLACK_TOKEN}`
},
body: JSON.stringify({
channel: `#${channel}`,
text: message
})
});

const data = await response.json();

if (data.ok) {
res.json({ success: true });
} else {
console.error('Slack API error:', data.error);
res.json({ success: false });
}
} catch (error) {
console.error('Error sending message:', error);
res.status(500).json({ success: false });
}
});

app.listen(3000, () => {
console.log('Server is running on port 3000');
});
63 changes: 63 additions & 0 deletions New_APIs/Slack API/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #4A154B, #36C5F0);
color: #333;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
}

header {
text-align: center;
margin-bottom: 20px;
}

header h1 {
font-size: 2.5em;
color: #fff;
}

main {
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
width: 300px;
}

form {
display: flex;
flex-direction: column;
gap: 10px;
}

input, textarea {
padding: 10px;
font-size: 1em;
border: 1px solid #ccc;
border-radius: 5px;
}

button {
padding: 10px;
font-size: 1em;
color: #fff;
background-color: #4A154B;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #36C5F0;
}

#status {
margin-top: 10px;
font-weight: bold;
color: #4A154B;
}
Loading