Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code with prettier and standardjs #19

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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`
- `node index.js` or `node pullIncomings.js`
1 change: 0 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -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
52 changes: 36 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -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({
72 changes: 43 additions & 29 deletions pullIncomings.js
Original file line number Diff line number Diff line change
@@ -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)
})