-
-
Save devrelv/44f5c430d54b31e4ede866f226537700 to your computer and use it in GitHub Desktop.
ngrok with viber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require("http"); | |
var options = { | |
hostname: '127.0.0.1', | |
port: 4040, | |
path: '/api/tunnels', | |
method: 'GET', | |
headers: { | |
'Content-Type': 'application/json', | |
} | |
}; | |
module.exports.getPublicUrl = function() { | |
return new Promise((resolve, reject) => { | |
var req = http.request(options, function(res) { | |
res.setEncoding('utf8'); | |
res.on('data', function(config) { | |
config = JSON.parse(config); | |
const httpsTunnel = config.tunnels.filter(t => t.proto === 'https').pop(); | |
resolve(httpsTunnel.public_url); | |
}); | |
}); | |
req.on('error', function(e) { | |
reject(e.message); | |
}); | |
req.end(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ngrok = require('./get_public_url'); | |
const ViberBot = require('./viber-bot').Bot; | |
// Creating the bot with access token, name and avatar | |
const bot = new ViberBot(logger, { | |
authToken: "YOUR_AUTH_TOKEN", | |
name: "YOUR_BOT_NAME", | |
avatar: "YOUR_BOT_AVATAR_URL" | |
}); | |
const http = require('http'); | |
const port = process.env.PORT || 8080; | |
return ngrok.getPublicUrl().then(publicUrl => { | |
console.log('Set the new webhook to"', publicUrl); | |
http.createServer(bot.middleware()).listen(port, () => bot.setWebhook(publicUrl)); | |
}).catch(error => { | |
console.log('Can not connect to ngrok server. Is it running?'); | |
console.error(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment