mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 08:47:40 -05:00
Add basic tweet-bot stuff
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
"mongoose": "5.11.10",
|
||||
"node-mailjet": "3.3.1",
|
||||
"passport": "0.4.1",
|
||||
"passport-local": "1.0.0"
|
||||
"passport-local": "1.0.0",
|
||||
"passport-twitter": "1.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
19
account/server/config/passport-strategies/twitter.js
Normal file
19
account/server/config/passport-strategies/twitter.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var Strategy = require('passport-twitter').Strategy;
|
||||
const User = require("../../models/user");
|
||||
|
||||
const twitter = new Strategy({
|
||||
consumerKey: process.env['TWITTER_CONSUMER_KEY'],
|
||||
consumerSecret: process.env['TWITTER_CONSUMER_SECRET'],
|
||||
callbackURL: '/oauth/callback',
|
||||
proxy: trustProxy
|
||||
},
|
||||
function(token, tokenSecret, profile, cb) {
|
||||
// In this example, the user's Twitter profile is supplied as the user
|
||||
// record. In a production-quality application, the Twitter profile should
|
||||
// be associated with a user record in the application's database, which
|
||||
// allows for account linking and authentication with other identity
|
||||
// providers.
|
||||
return cb(null, profile);
|
||||
})
|
||||
|
||||
module.exports = local;
|
||||
@@ -1,6 +1,7 @@
|
||||
/* Initializing PassportJS */
|
||||
const User = require("../models/user");
|
||||
const local = require("./passport-strategies/local");
|
||||
const twitter = require("./passport-strategies/twitter");
|
||||
|
||||
module.exports = function (app, passport) {
|
||||
// Configure Passport authenticated session persistence.
|
||||
|
||||
@@ -32,6 +32,7 @@ const server = require('http').createServer(app);
|
||||
|
||||
const io = require('socket.io')(server, {});
|
||||
|
||||
var Twitter = require('twitter-lite');
|
||||
|
||||
|
||||
io.origins('*:*');
|
||||
@@ -50,6 +51,23 @@ io.on('connection', function(socket){
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
const client = new Twitter({
|
||||
subdomain: "api", // "api" is the default (change for other subdomains)
|
||||
version: "1.1", // version "1.1" is the default (change for other subdomains)
|
||||
consumer_key: process.env.TWITTER_CONSUMER_KEY, // from Twitter.
|
||||
consumer_secret: process.env.TWITTER_CONSUMER_SECRET, // from Twitter.
|
||||
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY, // from your User (oauth_token)
|
||||
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET // from your User (oauth_token_secret)
|
||||
});
|
||||
|
||||
client
|
||||
.get("account/verify_credentials")
|
||||
.then(results => {
|
||||
console.log("results", results);
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
function getRole(req) {
|
||||
if (req.params.shortName && req.user) {
|
||||
var short_name = req.params.shortName.toLowerCase();
|
||||
@@ -156,8 +174,19 @@ app.post('/:shortName/star/:id', calls.add_star, function(req,res) {
|
||||
|
||||
|
||||
/*------ UPLOADS ---------- upload.single('call'), uploads.upload,*/
|
||||
app.post('/:shortName/upload', upload.single('call'), uploads.upload, function(req,res) {
|
||||
app.post('/:shortName/upload', upload.single('call'), uploads.upload, async function(req,res) {
|
||||
notify_clients(req.call);
|
||||
if ((req.call.shortName=="dcfd") && (req.call.talkgroupNum==101)) {
|
||||
var call_time = new Date(req.call.time);
|
||||
var call_link = "https://openmhz.com/system/dcfd?call-id=" + req.call._id + "&time=" + call_time.getTime();
|
||||
|
||||
var call_time_label = call_time.toLocaleDateString() + " " + call_time.toLocaleTimeString()
|
||||
var status = req.call.len +" sec transmission\n" + call_time_label + "\n" + call_link;
|
||||
const response = await client.post('statuses/update', {
|
||||
status: status,
|
||||
});
|
||||
//console.log("Tweet Response: " + response);
|
||||
}
|
||||
});
|
||||
|
||||
/*------ SYSTEMS ----------*/
|
||||
|
||||
@@ -65,6 +65,10 @@ services:
|
||||
- S3_ENDPOINT
|
||||
- S3_BUCKET
|
||||
- S3_PROFILE
|
||||
- TWITTER_CONSUMER_KEY
|
||||
- TWITTER_CONSUMER_SECRET
|
||||
- TWITTER_ACCESS_TOKEN_KEY
|
||||
- TWITTER_ACCESS_TOKEN_SECRET
|
||||
volumes:
|
||||
- "~/.aws:/home/app/.aws"
|
||||
depends_on:
|
||||
|
||||
@@ -22,3 +22,7 @@ export REACT_APP_ACCOUNT_SERVER="${PROTOCOL}account.${DOMAIN_NAME}"
|
||||
export REACT_APP_ADMIN_SERVER="${PROTOCOL}admin.${DOMAIN_NAME}"
|
||||
export REACT_APP_COOKIE_DOMAIN=".${DOMAIN_NAME}"
|
||||
|
||||
export TWITTER_CONSUMER_KEY=""
|
||||
export TWITTER_CONSUMER_SECRET=""
|
||||
export TWITTER_ACCESS_TOKEN_KEY=""
|
||||
export TWITTER_ACCESS_TOKEN_SECRET=""
|
||||
Reference in New Issue
Block a user