Slack
Bring Astrologie in Slack – mit einem Slash-Befehl, hinter dem die Occult API steckt.
Slack-App
Erstell unter api.slack.com/apps eine Slack-App und füg einen Slash-Befehl hinzu, zum Beispiel /horoscope. Als Befehls-URL trägst du den Endpoint deines Backends ein.
Endpoint
Lass den Slash-Befehl auf eine Route deines Servers zeigen, zum Beispiel https://your-domain.com/slack/horoscope.
Node.js-Handler
Ein Express-Handler, der die Occult API aufruft und das Ergebnis zurückgibt:
app.post('/slack/horoscope', async (req, res) => {
const text = req.body.text || 'aries';
const sign = text.trim().split(' ')[0];
const response = await fetch('https://api.occultapi.com/api/astro/rashifal/daily/', {
method: 'POST',
headers: { 'X-API-Key': process.env.OCCULT_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({ rashi: sign }),
});
const data = await response.json();
res.json({ response_type: 'in_channel', text: data.get_daily_rashifal.general_prediction });
});Verwendung
Tipp /horoscope leo in einem beliebigen Slack-Channel ein, und du bekommst das Tageshoroskop für Löwe.