Skip to content

Commit f57e137

Browse files
Prakhar Goelcursoragent
authored andcommitted
fix: replace dead exchangeratesapi endpoint and fix error message interpolation
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f75631d commit f57e137

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
@@ -9,12 +9,12 @@ var input = current.text.trim(); // Get entire user input after trimming
99
// Extract amount, fromCurrency, and toCurrency from the input
1010
var match = input.match(/!convert (\d+) (\w+) to (\w+)/);
1111
var amount = match ? match[1] : "";
12-
var fromCurrency = match ? match[2] : "";
13-
var toCurrency = match ? match[3] : "";
12+
var fromCurrency = match ? match[2].toUpperCase() : "";
13+
var toCurrency = match ? match[3].toUpperCase() : "";
1414

1515
// Build the search URL using the Currency Converter API
16-
var baseUrl = 'https://api.exchangeratesapi.io/latest';
17-
var searchUrl = baseUrl + '?base=' + fromCurrency;
16+
var baseUrl = 'https://api.frankfurter.dev/v1/latest';
17+
var searchUrl = baseUrl + '?base=' + fromCurrency + '&symbols=' + toCurrency;
1818

1919
// Make the API request
2020
var chatReq = new sn_ws.RESTMessageV2();
@@ -34,5 +34,5 @@ if (responseData.rates && responseData.rates[toCurrency]) {
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 {
37-
new x_snc_slackerbot.Slacker().send_chat(current, "Sorry, I couldn't find the exchange rate for ${fromCurrency} to ${toCurrency}.", false);
37+
new x_snc_slackerbot.Slacker().send_chat(current, "Sorry, I couldn't find the exchange rate for " + fromCurrency + " to " + toCurrency + ".", false);
3838
}

0 commit comments

Comments
 (0)