-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: création de sms-service (separation des responsabilités)
- Loading branch information
Showing
2 changed files
with
27 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import axios from "axios" | ||
import config from "../config/index.js" | ||
|
||
export async function renderAndSendSimulationResultsSms(followup) { | ||
try { | ||
const username = config.smsService.username | ||
const password = config.smsService.password | ||
if (!username || !password) { | ||
throw new Error("Missing SMS service credentials") | ||
} | ||
const renderUrl = followup.renderSimulationResultsSmsUrl(username, password) | ||
const axiosInstance = axios.create({ | ||
timeout: 10000, | ||
}) | ||
const { data, status } = await axiosInstance.get(renderUrl) | ||
if (status !== 200 || data.responseCode !== 0) { | ||
throw new Error(`SMS request failed. Body: ${JSON.stringify(data)}`) | ||
} | ||
return data.messageIds[0] | ||
} catch (err) { | ||
console.error(err) | ||
throw err | ||
} | ||
} |
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