Skip to content

Commit c5e7ec5

Browse files
Switch to Frankfurter API and format converted amount
Updated the API endpoint to use the Frankfurter API and modified the conversion amount to be formatted to two decimal places.
1 parent 3519bde commit c5e7ec5

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Parsers/Currency Converter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ var amount = match ? match[1] : "";
1212
var fromCurrency = match ? match[2] : "";
1313
var toCurrency = match ? match[3] : "";
1414

15-
// Build the search URL using the Currency Converter API
16-
var baseUrl = 'https://api.exchangeratesapi.io/latest';
17-
var searchUrl = baseUrl + '?base=' + fromCurrency;
15+
// Build the search URL using the Frankfurter API (free, no API key required)
16+
var baseUrl = 'https://api.frankfurter.app/latest';
17+
var searchUrl = baseUrl + '?from=' + fromCurrency + '&to=' + toCurrency;
1818

1919
// Make the API request
2020
var chatReq = new sn_ws.RESTMessageV2();
@@ -29,8 +29,8 @@ var responseData = JSON.parse(chatResponseBody);
2929
// Check if the API response contains exchange rates
3030
if (responseData.rates && responseData.rates[toCurrency]) {
3131
var exchangeRate = responseData.rates[toCurrency];
32-
var convertedAmount = amount * exchangeRate;
33-
32+
var convertedAmount = (amount * exchangeRate).toFixed(2);
33+
3434
// Send a formatted message to Slack
3535
new x_snc_slackerbot.Slacker().send_chat(current, `${amount} ${fromCurrency} is equal to ${convertedAmount.toFixed(2)} ${toCurrency}`, false);
3636
} else {

0 commit comments

Comments
 (0)