sai4teja3
(sai teja)
October 16, 2022, 5:23am
1
Hey, how to store the button payload to title value from a custom action
I have tried with the tracker.latest_message[‘text’] but it was not helpful to me.
My scenario is, I was making an API get call where I will display available doctors as buttons(and in every get call doctors’ names will be changed), My question is how to get the Payload or Title value that the user is selecting using custom actions.
Please help me I was stuck in this position.
Thank you in Advance
Hi, what is your current implementation of the custom actions?
sai4teja3
(sai teja)
October 16, 2022, 7:28am
3
In Custom action i was displaying Buttons using API call
Can you show the code of your current implementation?
You can use,
button = { 'title': word, 'payload': '/intent_name{'entity_name':"'+word+'"}'}
Add a custom action after this step where you can use,
doctor_name = next(tracker.get_latest_entity_values('entity_name'))
sai4teja3
(sai teja)
October 16, 2022, 7:55am
9
once see this action here i was creating intent name from API , now how can I store the Payload or Title to a Slot.
class ActionidSubmit(Action):
def name(self) -> Text:
return "action_book_appointment_submit"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
user_msg = tracker.latest_message.get('text')
print(tracker.get_slot("consulttype"))
buttons=[]
message=Get_Doctors(tracker.get_slot("id"),tracker.get_slot("consulttype"))
print(message)
for word in message.split(','):
button = {'title': word, 'payload': '/'+word+'{"Dname": "' + word + '"}'}
buttons.append(button)
dispatcher.utter_message(text="Your top 5 previous doctors are:",buttons=buttons)
return []
sai4teja3
(sai teja)
October 16, 2022, 7:58am
10
And in Every Api call the doctor names will be changed
rasa_learner
(sathishlakshmanan)
October 16, 2022, 8:20am
11
You have to change this,
to,
button = { 'title': word, 'payload': '/intent_name{'Dname':"'+word+'"}'} # add intent_name to domain
or you can directly use,
button = { 'title': word, 'payload': word}
sai4teja3
(sai teja)
October 16, 2022, 8:23am
12
For this one what will be the story to store the payload
if I use this how can I store the payload or title value
rasa_learner
(sathishlakshmanan)
October 16, 2022, 8:26am
13
button = { 'title': word, 'payload': word}
Add a custom action after this step where you can use,
doctor_name = tracker.latest_message.get('text')
sai4teja3
(sai teja)
October 16, 2022, 8:29am
14
I followed the same but it is returning None
rasa_learner
(sathishlakshmanan)
October 16, 2022, 8:30am
15
Please provide your implementation
sai4teja3
(sai teja)
October 16, 2022, 8:32am
16
class ActionidSubmit(Action):
def name(self) -> Text:
return "action_book_appointment_submit"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
user_msg = tracker.latest_message.get('text')
print(tracker.get_slot("consulttype"))
buttons=[]
message=Get_Doctors(tracker.get_slot("id"),tracker.get_slot("consulttype"))
print(message)
for word in message.split(','):
button = {'title': word, 'payload': word}
buttons.append(button)
text = tracker.latest_message.get("text")
dispatcher.utter_message(text="Your top 5 previous doctors are:",buttons=buttons)
return []
rasa_learner
(sathishlakshmanan)
October 16, 2022, 8:40am
17
This has to be implemented in a new custom action after this action
sai4teja3
(sai teja)
October 16, 2022, 10:24am
18
Yes you are Right but without the user selection of the buttons it is moving to another action within 3 seconds
rasa_learner
(sathishlakshmanan)
October 16, 2022, 10:27am
19
What do you mean by “within 3 seconds”?
sai4teja3
(sai teja)
October 16, 2022, 10:34am
20
It was moving to next action without the user selection of button
class ActionidSubmit(Action):
def name(self) -> Text:
return "action_book_appointment_submit"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
user_msg = tracker.latest_message.get('text')
print(tracker.get_slot("consulttype"))
buttons=[]
message=Get_Doctors(tracker.get_slot("id"),tracker.get_slot("consulttype"))
print(message)
for word in message.split(','):
button = {'title': word, 'payload': word}
buttons.append(button)
dispatcher.utter_message(text="Your top 5 previous doctors are:",buttons=buttons)
return [FollowupAction("action_name")]
class ActionTimeSubmit(Action):
def name(self) -> Text:
return "action_time_submit"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
text = tracker.latest_message.get("text")
print(text)
dispatcher.utter_message(text="Thank you")
return []