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 recent from './routes/recent';
|
||||||
import search from './routes/search';
|
import search from './routes/search';
|
||||||
import share from './routes/share';
|
import share from './routes/share';
|
||||||
|
import slack from './routes/slack';
|
||||||
import errorHandler from './lib/error-handler';
|
import errorHandler from './lib/error-handler';
|
||||||
|
|
||||||
const debug = debuglog('combine.fm');
|
const debug = debuglog('combine.fm');
|
||||||
|
@ -57,6 +58,8 @@ app.use(route.get('/recent', recent));
|
||||||
app.use(route.post('/search', search));
|
app.use(route.post('/search', search));
|
||||||
app.use(route.get('/:service/:type/:id.:format?', share));
|
app.use(route.get('/:service/:type/:id.:format?', share));
|
||||||
|
|
||||||
|
app.use(route.post('/slack', slack));
|
||||||
|
|
||||||
if (!module.parent) {
|
if (!module.parent) {
|
||||||
app.listen(process.env.PORT || 3000, () => {
|
app.listen(process.env.PORT || 3000, () => {
|
||||||
debug(`Koa HTTP server listening on port ${(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_ACCESS_KEY_ID:
|
||||||
AWS_SECRET_ACCESS_KEY:
|
AWS_SECRET_ACCESS_KEY:
|
||||||
AWS_TAG:
|
AWS_TAG:
|
||||||
|
SLACK_TOKEN:
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app:cached
|
- ./:/app:cached
|
||||||
- node_modules:/app/node_modules
|
- node_modules:/app/node_modules
|
||||||
|
@ -61,8 +62,6 @@ services:
|
||||||
POSTGRES_DB: "combinefm"
|
POSTGRES_DB: "combinefm"
|
||||||
redis:
|
redis:
|
||||||
image: "redis:4.0.2-alpine"
|
image: "redis:4.0.2-alpine"
|
||||||
ports:
|
|
||||||
- "6379:6379"
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
node_modules:
|
node_modules:
|
||||||
|
|
|
@ -38,14 +38,19 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h2 class="title is-2">Tools</h2>
|
<h2 class="title is-2">Tools</h2>
|
||||||
<div class="columns">
|
<p>
|
||||||
<p class="column is-half">
|
<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>
|
||||||
Download the Chrome Extension and get Combine.fm links right from your address bar.
|
</p>
|
||||||
</p>
|
<p>
|
||||||
<p class="column is-half">
|
Add to Slack and get links matched inline.
|
||||||
<a href="https://chrome.google.com/webstore/detail/kjfpkmfgcflggjaldcfnoppjlpnidolk"><img src="/assets/images/chrome-web-store.png" alt="Download the Chrome Extension" /></a>
|
</p>
|
||||||
</p>
|
<hr />
|
||||||
</div>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</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: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: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='twitter:image:src' property='og:image' content='<%=head.image%>' />
|
||||||
|
<meta name="slack-app-id" content="AA9SLSFFC">
|
||||||
<meta property='og:url' content='<%=head.shareUrl%>' />
|
<meta property='og:url' content='<%=head.shareUrl%>' />
|
||||||
<link rel='shortcut icon' href='/assets/images/favicon.png' />
|
<link rel='shortcut icon' href='/assets/images/favicon.png' />
|
||||||
<link rel='icon' sizes='512x512' href='/assets/images/logo-512.png' />
|
<link rel='icon' sizes='512x512' href='/assets/images/logo-512.png' />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue