Skip to content
Open
13 changes: 8 additions & 5 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ on:
workflow_dispatch:

schedule:
- cron: "44 16 * * *"
- cron: "45 16 * * *"
jobs:
autosend:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: "12.x"
node-version: '12'
- name: Install dependencies
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 'true'
run: npm install
- name: Cache multi paths
uses: actions/cache@v2
Expand All @@ -27,12 +29,13 @@ jobs:
key: ${{ secrets.CACHE_NAME }}-${{ github.run_id }}
restore-keys: ${{ secrets.CACHE_NAME }}-
- name: Run autosend
uses: mujo-code/puppeteer-headful@master
env:
TEXTNOW_USERNAME: ${{secrets.TEXTNOW_USERNAME}}
TEXTNOW_PASSWORD: ${{secrets.TEXTNOW_PASSWORD}}
TEXTNOW_COOKIES: ${{secrets.TEXTNOW_COOKIES}}
TEXTNOW_RECIPIENT: ${{secrets.TEXTNOW_RECIPIENT}}
TEXTNOW_MESSAGE: ${{secrets.TEXTNOW_MESSAGE}}
CAPTCHA_TOKEN: ${{secrets.CAPTCHA_TOKEN}}
run: |
node index.js
with:
args: npm start
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.cache
.idea
.env
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const actionFunc = async (
const puppeteer = require('puppeteer-extra');
const recaptchaPlugin = require('puppeteer-extra-plugin-recaptcha');
const stealthPlugin = require('puppeteer-extra-plugin-stealth');
const adblockerPlugin = require('puppeteer-extra-plugin-adblocker');
const textNowHelper = require('./utils/helper');

let browser = null;
Expand Down Expand Up @@ -33,25 +34,28 @@ const actionFunc = async (
}),
);
}
puppeteer.use(adblockerPlugin());

browser = await puppeteer.launch({
headless: true,
headless: false,
executablePath: process.env.PUPPETEER_EXEC_PATH,
args: [
process.env.HTTP_PROXY ?
`--proxy-server=${process.env.HTTP_PROXY}` :
'',
'--disable-features=IsolateOrigins,site-per-process',
'--flag-switches-begin --disable-site-isolation-trials --flag-switches-end',
'--no-sandbox',
],
});
page = await browser.newPage();
page.setDefaultNavigationTimeout(0);
const client = await page.target().createCDPSession();

try {
console.log('Importing cookies from environment...');
cookies = JSON.parse(Buffer.from(cookies, 'base64').toString());
} catch (error) {
console.log(`Environment cookies is invalid format: ${error}`);
cookies = null;
try {
console.log('Importing existing cookies from file...');
const cookiesString = await fs.readFile(
Expand All @@ -60,11 +64,15 @@ const actionFunc = async (
cookies = JSON.parse(cookiesString.toString());
} catch (error) {
console.log(`Failed to import existing cookies: ${error}`);
cookies = null;
}
}

// Log into TextNow and get cookies
try {
if (cookies === null) {
throw new Error("Cookies is null");
}
console.log('Logging in with existing cookies');
await page.setCookie(...cookies);
cookies = await textNowHelper.logIn(page, client);
Expand Down
Loading