From 53e0bd5c0f6ebb9cf002d48b239bfe02fb30fe12 Mon Sep 17 00:00:00 2001 From: cheetah Date: Wed, 21 Dec 2022 01:48:16 +0100 Subject: [PATCH] fixed new emessage interface change --- .../connectors/eMessagePuppeteerConnector.js | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/types/connectors/eMessagePuppeteerConnector.js b/types/connectors/eMessagePuppeteerConnector.js index 75db5cf..79c42dc 100644 --- a/types/connectors/eMessagePuppeteerConnector.js +++ b/types/connectors/eMessagePuppeteerConnector.js @@ -43,52 +43,67 @@ class eMessagePuppeteerConnectorBase extends Connector { this.connectorRegistry.reportState(msg, UUID, 'puppettering') const page = await browser.newPage() await page.goto('https://ruf.emessage.de/') - - const serviceSelect = 'select[name="pageSendForm:serviceSelect"]' - await page.waitForSelector(serviceSelect) - await page.select(serviceSelect, serviceName) - await page.click(serviceSelect) - await page.click(serviceSelect) - await sleep(1e3) - - const selectServiceButton = 'input[name="pageSendForm:selectServiceButton"]' - await page.waitForSelector(selectServiceButton) - await page.click(selectServiceButton) - await sleep(1e3) - - const pagerNumberInput = 'input[name="pageSendForm:pagerNumberInput"]' + + const pagerNumberInput = 'input[formcontrolname="eID"]' await page.waitForSelector(pagerNumberInput) await page.type(pagerNumberInput, identifier) await sleep(1e3) - const validatePagerNumberButton = 'input[id="pageSendForm:validatePagerNumberButton"]' + const validatePagerNumberButton = 'form > div:nth-child(2) > button:nth-child(1)' await page.waitForSelector(validatePagerNumberButton) await page.click(validatePagerNumberButton) await sleep(1e3) - const pageContentInput = 'textarea[id="pageSendForm:pageContentInput"]' + const localStorage = await page.evaluate(() => Object.assign({}, window.localStorage)) + + console.log(localStorage) + if (!!localStorage['token:ruf']) + await browser.close() + return axios.post('https://api.emessage.de/rs/ruf/send', { + messageText: payloadBuffer.toString('ascii'), + identifier + }, { + headers: { + 'Authorization': `Bearer ${ localStorage['token:ruf'] }` + } + }) + .then((sndMessageReq) => { // extract tracking ID from response + if (sndMessageReq.data.apiStatusCode != 200) { throw sndMessageReq } + let msgTrackID = sndMessageReq.data.data.trackingId + console.log('TRACKING ID', msgTrackID, sndMessageReq.data.data.recipients) + return res(msgTrackID) + }) + .catch((err) => { + console.error(err) + this.connectorRegistry.reportFail(msg, UUID) + return rej(err) + }) + +/* + const pageContentInput = 'textarea[formcontrolname="message"]' await page.waitForSelector(pageContentInput) await page.type(pageContentInput, payloadBuffer.toString('ascii')) await sleep(1e3) - const sendPageButton = 'input[id="pageSendForm:sendPageButton"]' + const sendPageButton = 'form > div:nth-child(3) > button:nth-child(2)' await page.waitForSelector(sendPageButton) await page.click(sendPageButton) await sleep(1e3) - const messageSentResult = 'span[id="pageSendForm:messageSentResult"]' + const messageSentResult = '.response-wrapper > div > p' await page.waitForSelector(messageSentResult) let $messageSentResult = await page.$(messageSentResult) let value = await page.evaluate(el => el.textContent, $messageSentResult) // pageSendForm:messageSentResult - if (value.indexOf("Meldung : OK") > -1) { + if (value.indexOf("Ihr Ruf wurde erfolgreich gesendet") > -1) { await browser.close() return res(true) } else { await browser.close() return rej(value) } + */ }) try {