-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): add support for Free mobile (#2285)
The french carrier Free propose to their customer an option allowing them to send HTTP GET requests to a gateway that will send in turn a text SMS to the customer phone. As the carrier API is purely web, and PHONE_NUMBER is irrelevant here, two new env parameters have been added: - FREEMOBILE_ID (Free mobile account id) - FREEMOBILE_API_KEY (API key provided with the option)
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {Link, Store} from '../store/model'; | ||
import {Print, logger} from '../logger'; | ||
import {config} from '../config'; | ||
import {URL} from 'url'; | ||
import fetch from 'node-fetch'; | ||
|
||
const {freemobile} = config.notifications; | ||
|
||
const url = new URL('https://smsapi.free-mobile.fr/sendmsg'); | ||
|
||
if (freemobile.id && freemobile.apiKey) { | ||
url.searchParams.append('user', freemobile.id); | ||
url.searchParams.append('pass', freemobile.apiKey); | ||
} | ||
|
||
export function sendFreeMobileAlert(link: Link, store: Store) { | ||
if (freemobile.id && freemobile.apiKey) { | ||
logger.debug('↗ sending free mobile alert'); | ||
|
||
(async () => { | ||
const color = false; | ||
const sms = true; | ||
|
||
const message = `${Print.inStock( | ||
link, | ||
store, | ||
color, | ||
sms | ||
)}\n${Print.productInStock(link)}`; | ||
|
||
url.searchParams.append('msg', message); | ||
|
||
try { | ||
const response = await fetch(url.toString(), { | ||
method: 'GET', | ||
}); | ||
|
||
const http200Success = await response.ok; | ||
if (!http200Success) throw Error(JSON.stringify(response)); | ||
|
||
logger.info('✔ free mobile alert sent'); | ||
} catch (error: unknown) { | ||
logger.error("✖ couldn't send free mobile alert", error); | ||
} | ||
})(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters