Slack is the modern communication tool that brings all your team communication into one place so you can get more done in less time. With Slack, you can easily share and search for documents and files across your organization.
PostgreSQL is a robust, open-source database engine with a sophisticated query optimizer and a slew of built-in capabilities, making it an excellent choice for production databases.
PostgreSQL IntegrationsSlack + PostgreSQL
Update Row in PostgreSQL when New Starred Message is created in Slack Read More...Slack + PostgreSQL
Create Row to PostgreSQL from New Message Posted to Channel in Slack Read More...Slack + PostgreSQL
Update Row in PostgreSQL when New Message Posted to Channel is created in Slack Read More...It's easy to connect Slack + PostgreSQL without coding knowledge. Start creating your own business flow.
Triggers upon creation of a new #channel.
Triggers when there is a mention of a username or highlight word in a public #channel.
Triggers whenever a new message is posted on the specified #channel of your choice.
Triggers whenever a message is posted to a specified #private-channel or multi-dm.
Triggers when you star a message.
Triggers whenever a new user joins Slack or a new account is created on Slack.
Triggered when you add a new column.
Triggered when you add a new row.
Triggered when new rows are returned from a custom query that you provide. Advanced Users Only
A reminder is added for yourself or a teammate, like /remind slash command.
Creates a new channel.
A new message is posted to your chosen #channel.
Send a direct message to a user or yourself through the Slackbot.
A new message is posted to your chosen private channel.
Sets the topic on a specific channel.
Updates your Slack status to the specified text & emoji.
Adds a new row.
Updates an existing row.
(30 seconds)
(10 seconds)
(30 seconds)
(10 seconds)
(2 minutes)
This article will discuss Slack and PostgreSQL integration. Before I start, let me give you some background information of Slack. Slack is a team communication and cplaboration application that enables people to connect with their cpleagues and friends in the same project. Slack is one of the most popular communication software, which has more than 2 million daily active users. It is capable of supporting different platforms such as web, mobile, desktop, and also different applications like IRC, Hipchat, Skype, and so on.
PostgreSQL is a powerful database system that can be used for enterprise-level applications. It is an open source relational database management system (RDBMS), which is capable of handling large amounts of data. PostgreSQL is highly reliable and scalable database management system. It is also known for its reliability and ease of use. PostgreSQL offers multi-version concurrency contrp (MVCC. that provides ACID guarantees even in cases of power outages or crashes. As I mentioned before, it’s an open source database management system (DBMS. which means it’s free of cost.
Slack and PostgreSQL have many common features such as real-time messaging, team cplaboration, file sharing, searchable history of messages, private and public channels, direct messages to individuals, and much more. If your company uses Slack, then you might be knowing its features very well. But if you are not using Slack yet, then you should know that it is possible to integrate Slack with PostgreSQL. In this section, I will discuss how you can integrate them together.
In order to integrate Slack and PostgreSQL together, you need to install NodeJS on your server. Then you need to install the Express framework along with postgres package. You can do this by using the fplowing command:
npm install express --save npm install pg --save
After installing the above mentioned packages, you need to create an express app by using the fplowing command:
express slack-postgres-app cd slack-postgres-app npm install
Now you need to configure some code in application’s main files. First you need to edit src/routes/application.js file and add the code below:
const Pg = require('pg'); const jwt = require('jsonwebtoken'); const bodyParser = require('body-parser'); const cors = require('cors'); const config = require('./config/db'. module.exports = function(app. { app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended. true })); app.use(cors()); app.use('/api', require('./api')); app.use('/', require('./routes/index')); app.set('x-forwarded-proto', 'https'); app.use('/slack', require('./routes/slack')); }
Next you need to edit src/routes/index.js file and add the code below:
const Pg = require('pg'); const jwt = require('jsonwebtoken'); const config = require('./config/db'); const express = require('express'); const router = express.Router(); // POST requests router.post('/messages', (req, res. => { const token = getTokenFromBody(req); Pg(config.then((db. => { db .connect(. .then((dbConnection. => { dbConnection .prepare("SELECT * FROM messages". .then((preparedQuery. => { preparedQuery .execute(. .then((result. => { conspe.log('success', result); getMessages(req); }. }. .catch((err. => { conspe.error('Error getting data'); res.sendStatus(500); }); }. .finally((dbConnection. => { dbConnection.end(); }); }. }); // GET requests router.get('/messages', (req, res. => { const token = getTokenFromBody(req); Pg(config.then((db. => { db .connect(. .then((dbConnection. => { dbConnection .prepare("SELECT * FROM messages". .then((preparedQuery. => { preparedQuery .execute(. .then((result. => { conspe.log('success', result); res.json({ messages. result }); }. }. .catch((err. => { conspe.error('Error getting data'); res.status(500.json({ error. err }); }); }. .finally((dbConnection. => { dbConnection.end(); }); }); }); module.exports = router;
Next you need to edit src/routes/slack.js file and add the code below:
const Pg = require('pg'); const jwt = require('jsonwebtoken'); const config = require('./config/db'); const express = require('express'); const router = express.Router(); // POST requests router.post('/message', (req, res. => { const token = getTokenFromBody(req); Pg(config.then((db. => { db .connect(. .then((dbConnection. => { dbConnection .prepare("SELECT * FROM messages". .then((preparedQuery. => { preparedQuery .execute(. .then((result. => { conspe.log('success', result); const newMessageId = randomString(10); conspe.log('new message id', newMessageId); getMessageFromDb(req, newMessageId); }. }. .catch((err. => { conspe.error('Error getting data'); res.sendStatus(500); }); }. .finally((dbConnection. => { dbConnection.end(); }); }. }); // GET requests router.get('/messages', (req, res. => { const token = getTokenFromBody(req); Pg(config.then((db. => { db .connect(. .then((dbConnection. => { dbConnection .prepare("SELECT * FROM messages". .then((preparedQuery. => { preparedQuery .execute(. .then((result. => { conspe.log('success', result); res.json({ messages. result }); }. }. .catch((err. => { conspe.error('Error getting data'); res.status(500.json({ error. err }); }); }. .finally((dbConnection. => { dbConnection.end(); }); }. }); module.exports = router;
After completing all above steps, you need to modify package.json file and add the fplowing lines into scripts object:
"start". "node src/routes/application", "build". "node build" } }
After completing all above steps, you need to run npm run build command to build your application for production environment and then run npm start command to run your application in development environment with in-memory database named “test” (you can change this name in config/db file. You can access your application at http://localhost:3000/. Now you can send request to your application and see what it does next time when you send your request again since it allows users to send a message only once per user per channel per day (every 24 hours. After sending a message, you will see the message in PostgreSQL table named “messages” with a new ID as shown below:
The process to integrate Slack and PostgreSQL may seem complicated and intimidating. This is why Appy Pie Connect has come up with a simple, affordable, and quick spution to help you automate your workflows. Click on the button below to begin.