Skip to content

Instantly share code, notes, and snippets.

if((page.url()==(req.body.sigspace+'/connectors/new?kind=agora')) && (await page.$eval('h1', el => el.innerText) == "Whoops!")){
reply += "OOPS! The SignalWire Server is down. Try again later.";
}
await page.waitForSelector('#relay_connector_name')
await page.type('#relay_connector_name', req.body.connectorname);
await page.waitForSelector('#relay_connector_token')
await page.type('#relay_connector_token', req.body.appid);
await page.keyboard.press('Enter').then(async () => { await page.waitForNavigation({waitUntil: 'load'})}).catch(()=>{console.log("FAIL")});
connect = '.text-center > a'
await page.waitForSelector(connect).then(()=>{console.log("Success!")}).catch(()=>{console.log("All numbers exhausted!")})
connectlink = await page.$$eval(connect, am => am.filter(e => e.href).map(e => e.href))
await page.goto(connectlink[0]);
connect = '.card-footer > a'
await page.waitForSelector(connect)
connectlink = await page.$$eval(connect, am => am.filter(e => e.href).map(e => e.href))
await page.goto(connectlink[2]);
let connect = '#navExpand > ul > li > a'
await page.waitForSelector(connect)
let connectlink = await page.$$eval(connect, am => am.filter(e => e.href).map(e => e.href))
await page.goto(connectlink[6]);
await page.select('#phone_route_voice_handler', 'relay_agora').then(async()=>{ console.log("SUCCESS!")}).catch(()=>{console.log("FAILED TO SELECT AGORA CONNECTOR")});
await page.select("select#phone_route_call_agora_connector_id", req.body.connectorname)
const input = await page.$('#phone_route_call_agora_channel');
await input.click({ clickCount: 3 })
await input.type(req.body.channel);
await page.$eval('input[name=commit]', el => el.click()).then(async()=>{ await page.waitForNavigation({waitUntil: 'load'})}).catch(()=>{console.log("SUCCESS")});;
await browser.close();
reply += "Call on: " + ans;
await res.send(reply);
await setTimeout((function() {
connect = '.col-4 > a'
await page.waitForSelector(connect)
connectlink = await page.$$eval(connect, am => am.filter(e => e.href).map(e => e.href))
await page.goto(connectlink[0]);
const num = await page.$eval('h1', el => el.innerText);
ans = num;
console.log(num);
connect = '.text-lg-right.mt-3 > a'
await page.waitForSelector(connect)
connectlink = await page.$$eval(connect, am => am.filter(e => e.href).map(e => e.href))
if(links[1]=='https://ramshri.signalwire.com/phone_numbers/new' || links[2]=='https://ramshri.signalwire.com/phone_numbers/new')
{
if(link[1]=='https://ramshri.signalwire.com/phone_numbers/new')
{
await page.goto(links[1])
}
else
{
await page.goto(links[2])
}
await page.goto(req.body.sigspace);
await page.type('#company_email', req.body.login);
await page.type('#company_password', req.body.pass);
await page.keyboard.press('Enter').then(async () => { await page.waitForNavigation({waitUntil: 'load'})}).catch(()=>{console.log("Couldn't log in")});
const selector = '.col-4 > a'
await page.waitForSelector(selector)
const links = await page.$$eval(selector, am => am.filter(e => e.href).map(e => e.href))
console.log(links);
let ans="empty";
app.post('/thank', urlencodedParser, async function (req, res){
var reply='';
async function main(){
const browser = await puppeteer.launch({
headless: true,
// slowMo: 0, // slow down by 250ms
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
app.get('*', function (req, res) {
var html='';
html += "<form action='/thank' method='post' name='form1'>";
html += "<label for='sigspace'>SignalWire Space:</label><br>";
html += "<input type='text' name='sigspace'><br>";
html += "<label for='login'>SignalWire email ID:</label><br>";
html += "<input type='text' name='login'><br>";
html += "<label for='pass'>SignalWire password:</label><br>";
html += "<input type='password' name='pass'><br>";
html += "<label for='areanum'>Area code:</label><br>";