Action.py

need help how could i write this code : http://data.fixer.io/api/convert ? access_key = API_KEY & from = GBP & to = JPY & amount = 25 on action.py :

This files contains your custom actions which can be used to run

custom Python code.

See this guide on how to implement these action:

Actions

from typing import Any, Text, Dict, List from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher #from rasa_sdk.events import Slotset

class ActionHelloWorld(Action):

def name(self) -> Text:
    return "action_hello_world"

def run(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    
   montant = tracker.get_slot("montant")
   devise = tracker.get_slot("devise")
   result_amount = 3000
   ###########################################
   





   ############################################
   

   dispatcher.utter_message("le montant {} en {} sera {} en DT".format(montant,devise, result_amount))
   #dispatcher.utter_message("ceci est my action 3")
   
   #return[Slotset("devise",devise)] 
   return[]

Hello @rawnak, Welcome to the community :blush:
Can you elaborate it more please? From what I gathered you are asking how to make an API call in your action.py file, well in that case you would have to read the documentation of that api. in action.py you can just write python code the same way you would somewhere else :slightly_smiling_face:

Here is a example of an api call in python:

import requests
url = 'http://data.fixer.io/api/latest'

data = {
    'access_key': 'YOUR API KEY HERE',
    "base":"EUR",
    'symbols': "USD,AUD,CAD,PLN",

}

it will show the latest rates based in EUR (output below)

Hope it helps.

1 Like

this is really help me thanks