Sure @nik202! Here’s an example:
class ActionUtterServiceTypes(Action):
def name(self):
return 'action_utter_service_types'
def run(self, dispatcher, tracker, domain):
announce(self, tracker)
text = get_text_from_lang(
tracker,
[['How can I help you today?', 'So I can get you to the right place, tell me what service you’d like help with.', 'How can I help?'],
['Comment puis-je vous aider?', 'Pour que je puisse vous guider, dites-moi pour quel service vous aimeriez obtenir de l’aide.', 'Comment puis-je aider?'],
['حتى أتمكن من إيصالك إلى المكان الصحيح ، أخبرني بالخدمة التي ترغب في المساعدة فيها.', 'كيف يمكنني أن أقدم المساعدة؟'],
['Այսպիսով, ես կարող եմ ձեզ ճիշտ տեղ հասցնել, ասեք ինձ, թե որ ծառայության հետ կցանկանայիք օգնել', 'Ինչպե՞ս կարող եմ օգնել:']]
)
buttons = get_buttons_from_lang(
tracker,
[['Wireless', 'Internet', 'DSL Internet', 'CableVision TV'],
['Sans Fil', 'Internet', 'Internet DSL', 'CableVision TV'],
['لاسلكي','إنترنت','DSL إنترنت','تلفزيون الكابل'],
['Անլար', 'Ինտերնետ', 'DSL ինտերնետ', 'CableVision TV']],
[
'/inform_service_type{"service_type": "wireless"}',
'/inform_service_type{"service_type": "internet"}',
'/inform_service_type{"service_type": "dsl"}',
'/inform_service_type{"service_type": "cablevision"}'
])
print('\nBOT:', text, buttons)
dispatcher.utter_message(text = text, buttons = buttons)
return []
Basically the get_text_from_lang
and get_buttons_from_lang
functions access the language
slot and return the text or button depending on its value.
get_text_from_lang
takes in a list of lists, each list represents a language, and each element inside it will be chosen randomly, like when writing multiple values for a response in the domain.
get_buttons_from_lang
takes in a list of lists and a second list. The first list of lists are the button titles in the different languages, and the second list is a list of payloads. Meaning, in the example above, ‘Wireless’ and ‘Sans Fil’ buttons both have the payload /inform_service_type{"service_type": "wireless"}
. ‘Wireless’ will appear if the bot is speaking English, and ‘Sans Fil’ will appear if it speaks French.
And this is the whole chatbot if you’d like to see more of the code: ChrisRahme/fyp-chatbot.