From cc298ee60a7ca40bb88105dfb2a19f7ae5dda45b Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 7 Feb 2023 10:24:16 +0000 Subject: [PATCH] Format code with prettier and standardjs This commit fixes the style issues introduced in 1a726f5 according to the output from prettier and standardjs. Details: https://deepsource.io/gh/LaReserveTech/lightsoff-contact-commercants/transform/dd8176d3-50fd-43ca-820e-8370977d1586/ --- .eslintrc.json | 24 +++++++--------- CODE_OF_CONDUCT.md | 22 +++++++------- CONTRIBUTING.md | 10 ++++--- README.md | 4 ++- SECURITY.md | 1 - index.js | 52 ++++++++++++++++++++++----------- pullIncomings.js | 72 +++++++++++++++++++++++++++------------------- 7 files changed, 110 insertions(+), 75 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index bb06996..c56c5d4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,15 +1,13 @@ { - "env": { - "browser": true, - "commonjs": true, - "es2021": true - }, - "extends": "standard-with-typescript", - "overrides": [ - ], - "parserOptions": { - "ecmaVersion": "latest" - }, - "rules": { - } + "env": { + "browser": true, + "commonjs": true, + "es2021": true + }, + "extends": "standard-with-typescript", + "overrides": [], + "parserOptions": { + "ecmaVersion": "latest" + }, + "rules": {} } diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index c7550c5..7ab2e69 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community. Examples of behavior that contributes to a positive environment for our community include: -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the +- Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: -* The use of sexualized language or imagery, and sexual attention or +- The use of sexualized language or imagery, and sexual attention or advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an +standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f4d9481..517a745 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,6 @@ To get an overview of the project, read the [README](README.md). Here are some r - [GitHub flow](https://docs.github.com/en/get-started/quickstart/github-flow) - [Collaborating with pull requests](https://docs.github.com/en/github/collaborating-with-pull-requests) - ## Getting started To navigate our codebase with confidence, see [the introduction to working in the docs repository](/contributing/working-in-docs-repository.md) :confetti_ball:. For more information on how we write our Markdown files, see [the GitHub Markdown reference](contributing/content-markup-reference.md). @@ -49,7 +48,9 @@ For more information about using a codespace for working on GitHub documentation #### Make changes locally 1. Fork the repository. + - Using GitHub Desktop: + - [Getting started with GitHub Desktop](https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/getting-started-with-github-desktop) will guide you through setting up Desktop. - Once Desktop is set up, you can use it to [fork the repository](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/cloning-and-forking-repositories-from-github-desktop)! @@ -67,10 +68,11 @@ Commit the changes once you are happy with them. Don't forget to [self-review](/ ### Pull Request When you're finished with the changes, create a pull request, also known as a PR. + - Fill the "Ready for review" template so that we can review your PR. This template helps reviewers understand your changes as well as the purpose of your pull request. - Don't forget to [link PR to issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) if you are solving one. - Enable the checkbox to [allow maintainer edits](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork) so the branch can be updated for a merge. -Once you submit your PR, a Docs team member will review your proposal. We may ask questions or request additional information. + Once you submit your PR, a Docs team member will review your proposal. We may ask questions or request additional information. - We may ask for changes to be made before a PR can be merged, either using [suggested changes](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/incorporating-feedback-in-your-pull-request) or pull request comments. You can apply suggested changes directly through the UI. You can make any other changes in your fork, then commit them to your branch. - As you update your PR and apply changes, mark each conversation as [resolved](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request#resolving-conversations). - If you run into any merge issues, checkout this [git tutorial](https://github.com/skills/resolve-merge-conflicts) to help you resolve merge conflicts and other issues. @@ -91,5 +93,5 @@ This site can be developed on Windows, however a few potential gotchas need to b 2. Paths: Windows systems use `\` for the path separator, which would be returned by `path.join` and others. You could use `path.posix`, `path.posix.join` etc and the [slash](https://ghub.io/slash) module, if you need forward slashes - like for constructing URLs - or ensure your code works with either. 3. Bash: Not every Windows developer has a terminal that fully supports Bash, so it's generally preferred to write [scripts](/script) in JavaScript instead of Bash. 4. Filename too long error: There is a 260 character limit for a filename when Git is compiled with `msys`. While the suggestions below are not guaranteed to work and could cause other issues, a few workarounds include: - - Update Git configuration: `git config --system core.longpaths true` - - Consider using a different Git client on Windows + - Update Git configuration: `git config --system core.longpaths true` + - Consider using a different Git client on Windows diff --git a/README.md b/README.md index 7adfc8b..9d14354 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,13 @@ [![CodeQL](https://github.com/LaReserveTech/lightsoff-contact-commercants/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/LaReserveTech/lightsoff-contact-commercants/actions/workflows/github-code-scanning/codeql) This repository contains two scripts : + - `index.js` to sending SMS or Programmatic Voice Call to commercants - `pullIncomings.js` to pull responses received by SMS ## Setup + - `npm install` - Download 'places.json' and 'reviews.json' from Metabase - Fill .env file -- `node index.js` or `node pullIncomings.js` \ No newline at end of file +- `node index.js` or `node pullIncomings.js` diff --git a/SECURITY.md b/SECURITY.md index 68d2a4b..8ceb492 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,7 +6,6 @@ | ------- | ------------------ | | 0.0.1 | :white_check_mark: | - ## Reporting a Vulnerability If you have foudn a vulnerability, please create an issue with all informations needed to fix that diff --git a/index.js b/index.js index 0fb2062..4a6e56e 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,8 @@ const places = require('./places.json') const axios = require('axios') const PNF = require('google-libphonenumber').PhoneNumberFormat -const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance() +const phoneUtil = + require('google-libphonenumber').PhoneNumberUtil.getInstance() require('dotenv').config() @@ -19,42 +20,61 @@ const ovh = require('ovh')({ }) const findPlaceById = (id) => { - const key = Object.keys(places).find(place => places[place]['Google Place ID'] === id) + const key = Object.keys(places).find( + (place) => places[place]['Google Place ID'] === id + ) return places[key] } const findOtherReviews = (id) => { - const key = Object.keys(reviews).find(review => reviews[review]['Google Place ID'] === id && reviews[review]['Do It For Me'] === false) + const key = Object.keys(reviews).find( + (review) => + reviews[review]['Google Place ID'] === id && + reviews[review]['Do It For Me'] === false + ) return reviews[key] } const placesContacted = [] // array temporaire pour stocker les lieux déjà contactés au cours du run actuel de l'algo -reviews.forEach(review => { +reviews.forEach((review) => { if (placesContacted <= 100) { const googlePlaceId = review['Google Place ID'] // stockage du Google Place ID de la review traitée en cours // on check si on est bien sur une review ou on nous a demandé de contacter le commerce + qu'il n'y a pas d'autres reviews déjà existantes + que le numéro n'a pas déjà été contacté - if (review['Do It For Me'] === true && findOtherReviews(googlePlaceId) === undefined && placesContacted.find(id => id === googlePlaceId) === undefined) { + if ( + review['Do It For Me'] === true && + findOtherReviews(googlePlaceId) === undefined && + placesContacted.find((id) => id === googlePlaceId) === undefined + ) { const place = findPlaceById(googlePlaceId) // on stock la Google Place const phoneNumberNotFormatted = place['Phone Number'] // on stock le numéro associé à la Google Place // on check si le numéro n'est pas vide if (phoneNumberNotFormatted !== null) { - const number = phoneUtil.parseAndKeepRawInput(phoneNumberNotFormatted, 'FR') // on formate correctement le numéro pour Twilio/OVH + const number = phoneUtil.parseAndKeepRawInput( + phoneNumberNotFormatted, + 'FR' + ) // on formate correctement le numéro pour Twilio/OVH const phoneNumber = phoneUtil.format(number, PNF.E164) // évaluation du numéro : si fixe => appel / si portable => SMS if (phoneNumber[3] === '6' || phoneNumber[3] === '7') { - ovh.request('POST', '/sms/' + process.env.OVH_SERVICE_NAME + '/jobs', { - message: 'Bonjour, plusieurs clients ont indiqué que la devanture de votre commerce restait allumée la nuit. Si c’est le cas, auriez-vous la gentillesse de l’éteindre en partant le soir ? Nous sommes en pleine crise énergétique et il est essentiel que nous fassions tous attention à faire des économies d’énergie pour éviter les coupures cet hiver et préserver notre planète. Chaque geste compte. En plus, depuis février 2022 la loi a été endurcie et vous risquez une forte amende en cas de contrôle. Bonne journée.', - senderForResponse: true, - noStopClause: true, - tag: 'Contact SMS LightsOff', - receivers: [phoneNumber] - }, function (errsend, result) { - console.log(errsend, result) - }) + ovh.request( + 'POST', + '/sms/' + process.env.OVH_SERVICE_NAME + '/jobs', + { + message: + 'Bonjour, plusieurs clients ont indiqué que la devanture de votre commerce restait allumée la nuit. Si c’est le cas, auriez-vous la gentillesse de l’éteindre en partant le soir ? Nous sommes en pleine crise énergétique et il est essentiel que nous fassions tous attention à faire des économies d’énergie pour éviter les coupures cet hiver et préserver notre planète. Chaque geste compte. En plus, depuis février 2022 la loi a été endurcie et vous risquez une forte amende en cas de contrôle. Bonne journée.', + senderForResponse: true, + noStopClause: true, + tag: 'Contact SMS LightsOff', + receivers: [phoneNumber] + }, + function (errsend, result) { + console.log(errsend, result) + } + ) // on ajoute une review SMS sur l'api axios({ @@ -69,7 +89,7 @@ reviews.forEach(review => { to: phoneNumber, from: phoneNumberVoiceFrom }) - .then(call => console.log(call.sid)) + .then((call) => console.log(call.sid)) // on ajoute une review PHONE CALL sur l'api axios({ diff --git a/pullIncomings.js b/pullIncomings.js index 98d5867..6e1a43b 100644 --- a/pullIncomings.js +++ b/pullIncomings.js @@ -8,39 +8,53 @@ const axios = require('axios') const tempData = async () => { return new Promise((resolve, reject) => { - ovh.request('GET', '/sms/' + process.env.OVH_SERVICE_NAME + '/incoming', function (err, data) { - if (err) { - reject(err) - } else { - resolve(data) + ovh.request( + 'GET', + '/sms/' + process.env.OVH_SERVICE_NAME + '/incoming', + function (err, data) { + if (err) { + reject(err) + } else { + resolve(data) + } } - }) + ) }) } -tempData().then(messages => { - messages.forEach(messageID => { - ovh.request('GET', '/sms/' + process.env.OVH_SERVICE_NAME + '/incoming/' + messageID, function (err, msgText) { - if (err) { - console.log(err) - } else { - axios({ - method: 'post', - url: process.env.SLACK_WEBHOOK, - headers: { 'Content-type': 'application/json' }, - data: { text: msgText.message } - }) - } - }) +tempData() + .then((messages) => { + messages.forEach((messageID) => { + ovh.request( + 'GET', + '/sms/' + process.env.OVH_SERVICE_NAME + '/incoming/' + messageID, + function (err, msgText) { + if (err) { + console.log(err) + } else { + axios({ + method: 'post', + url: process.env.SLACK_WEBHOOK, + headers: { 'Content-type': 'application/json' }, + data: { text: msgText.message } + }) + } + } + ) - ovh.request('DELETE', '/sms/' + process.env.OVH_SERVICE_NAME + '/incoming/' + messageID, function (err, res) { - if (err) { - console.log(err) - } else { - console.log('Réponse supprimée : ' + messageID) - } + ovh.request( + 'DELETE', + '/sms/' + process.env.OVH_SERVICE_NAME + '/incoming/' + messageID, + function (err, res) { + if (err) { + console.log(err) + } else { + console.log('Réponse supprimée : ' + messageID) + } + } + ) }) }) -}).catch(err => { - console.error(err) -}) + .catch((err) => { + console.error(err) + })