Add Slack support
This commit is contained in:
parent
18021e0ef8
commit
24c9363f0c
5 changed files with 72 additions and 10 deletions
3
app.js
3
app.js
|
@ -16,6 +16,7 @@ import index from './routes/index';
|
|||
import recent from './routes/recent';
|
||||
import search from './routes/search';
|
||||
import share from './routes/share';
|
||||
import slack from './routes/slack';
|
||||
import errorHandler from './lib/error-handler';
|
||||
|
||||
const debug = debuglog('combine.fm');
|
||||
|
@ -57,6 +58,8 @@ app.use(route.get('/recent', recent));
|
|||
app.use(route.post('/search', search));
|
||||
app.use(route.get('/:service/:type/:id.:format?', share));
|
||||
|
||||
app.use(route.post('/slack', slack));
|
||||
|
||||
if (!module.parent) {
|
||||
app.listen(process.env.PORT || 3000, () => {
|
||||
debug(`Koa HTTP server listening on port ${(process.env.PORT || 3000)}`);
|
||||
|
|
|
@ -20,6 +20,7 @@ services:
|
|||
AWS_ACCESS_KEY_ID:
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
AWS_TAG:
|
||||
SLACK_TOKEN:
|
||||
volumes:
|
||||
- ./:/app:cached
|
||||
- node_modules:/app/node_modules
|
||||
|
@ -61,8 +62,6 @@ services:
|
|||
POSTGRES_DB: "combinefm"
|
||||
redis:
|
||||
image: "redis:4.0.2-alpine"
|
||||
ports:
|
||||
- "6379:6379"
|
||||
|
||||
volumes:
|
||||
node_modules:
|
||||
|
|
|
@ -38,14 +38,19 @@
|
|||
</div>
|
||||
<div>
|
||||
<h2 class="title is-2">Tools</h2>
|
||||
<div class="columns">
|
||||
<p class="column is-half">
|
||||
Download the Chrome Extension and get Combine.fm links right from your address bar.
|
||||
</p>
|
||||
<p class="column is-half">
|
||||
<a href="https://chrome.google.com/webstore/detail/kjfpkmfgcflggjaldcfnoppjlpnidolk"><img src="/assets/images/chrome-web-store.png" alt="Download the Chrome Extension" /></a>
|
||||
</p>
|
||||
</div>
|
||||
<p>
|
||||
<a href="https://slack.com/oauth/authorize?client_id=349358389361.349904899522&scope=links:read,chat:write:bot"><img alt="Add to Slack" height="40" width="139" src="https://platform.slack-edge.com/img/add_to_slack.png" srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x" /></a>
|
||||
</p>
|
||||
<p>
|
||||
Add to Slack and get links matched inline.
|
||||
</p>
|
||||
<hr />
|
||||
<p>
|
||||
<a href="https://chrome.google.com/webstore/detail/kjfpkmfgcflggjaldcfnoppjlpnidolk"><img src="/assets/images/chrome-web-store.png" alt="Download the Chrome Extension" height="75" width="248" /></a>
|
||||
</p>
|
||||
<p>
|
||||
Download the Chrome Extension and get Combine.fm links right from your address bar.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
54
routes/slack.js
Normal file
54
routes/slack.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
import kue from 'kue';
|
||||
import request from 'superagent';
|
||||
import debuglog from 'debug';
|
||||
import { inspect } from 'util';
|
||||
|
||||
import lookup from '../lib/lookup';
|
||||
import services from '../lib/services';
|
||||
import { find, create } from '../lib/share';
|
||||
|
||||
const debug = debuglog('combine.fm:slack');
|
||||
|
||||
const queue = kue.createQueue({
|
||||
redis: process.env.REDIS_URL,
|
||||
});
|
||||
|
||||
const slackToken = process.env.SLACK_TOKEN;
|
||||
|
||||
export default async function (ctx) {
|
||||
if (ctx.request.body.challenge) {
|
||||
ctx.body = ctx.request.body.challenge;
|
||||
return;
|
||||
}
|
||||
|
||||
for (const link of ctx.request.body.event.links) {
|
||||
if (link.domain === 'combine.fm') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const music = await lookup(link.url);
|
||||
debug(music);
|
||||
const payload = {
|
||||
channel: ctx.request.body.event.channel,
|
||||
attachments: [
|
||||
{
|
||||
color: '#FE4365',
|
||||
author_name: `${music.name} by ${music.artist.name}`,
|
||||
author_link: `https://combine.fm/${music.service}/${music.type}/${music.id}`,
|
||||
author_icon: music.artwork.small,
|
||||
},
|
||||
]
|
||||
}
|
||||
try {
|
||||
const { body } = await request.post('https://slack.com/api/chat.postMessage')
|
||||
.set('Authorization', `Bearer ${slackToken}`)
|
||||
.send(payload);
|
||||
debug(body)
|
||||
} catch (err) {
|
||||
debug(err);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.body = 'OK';
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
<meta name='twitter:title' property='og:title' content='Combine.fm • <%=head.title%>' />
|
||||
<meta name='twitter:description' property='og:description' content='Combine.fm matches album and track links from Youtube, Spotify, Google Music, Apple Music, Amazon Music and Deezer and gives you back one link with matches we find on all of them.' />
|
||||
<meta name='twitter:image:src' property='og:image' content='<%=head.image%>' />
|
||||
<meta name="slack-app-id" content="AA9SLSFFC">
|
||||
<meta property='og:url' content='<%=head.shareUrl%>' />
|
||||
<link rel='shortcut icon' href='/assets/images/favicon.png' />
|
||||
<link rel='icon' sizes='512x512' href='/assets/images/logo-512.png' />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue