-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0815fe5
commit 679e9b4
Showing
6 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'; | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |