Sign in Authentication with Rasa

Can you give me some way or docs on that because when I typed Login it executed Username and Password as None without asking from user.

One way to do is to trigger a custom action when the user says book something. The story would be something like this:

  • Request booking
    • action_check_type
  • Credentials check
    • action_check_credentials

When the user says I want to book a bus or train, action_check_type will be triggered. In the action store the user’s message and see what type of booking he wants like a bus, fight, etc. Use dispatcher_utter_message to ask him for the credentials in the same action. Once he enters his details, action_check_credentials will be triggered and in that, you can have conditions for a bus, train, flight etc and make a reservation based on the previously extracted information from action_check_type. Alternatively, you can use custom slots to capture entities like a bus, plane/flight, train etc and use that information in your booking action.

  • Request booking
    • utter_ask_credentials
  • Credentials check
    • action_check_credentials

Hey I am facing issue. Can you give me some sample code for that I want to purchase ticket if purchase token is not available in payload then it should ask login from user.

Hi Paul , I want to get the user info like ID , Name when the user logs inn the websit . I am using Wbchat for that . I want to get UserID from the backend to make api calls .

Detail Rasa 1.6.1

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

This is a simple example for a custom action which utters “Hello World!”

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker

from rasa_sdk.executor import CollectingDispatcher

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]]:

dispatcher.utter_message(text=“Hello World!”)

return []

from future import absolute_import from future import division from future import unicode_literals

from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher

from rasa.core.actions.action import Action from rasa.core.events import SlotSet from rasa_sdk import Tracker from rasa_sdk.executor import CollectingDispatcher

from typing import Dict, Text, Any, List import requests from rasa_sdk import Action from rasa_sdk.events import SlotSet, FollowupAction from rasa_sdk.forms import FormAction #Tracker keep track of the slots in conversation.

#class getjoiningdate(Action):

def name(self):

return ‘get_joining_date’

def run(self, dispatcher, tracker, domain):

import pyodbc

#connecting to SQL server

conn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0}; \

SERVER=.;\

DATABASE=rasa_storge_new;\

UID=sa;\

PWD=pass@123;\

"Trusted_Conenection=yes;’)

cursor = conn.cursor()

#storing the user ID in “user_id”

user_id =tracker.get_slot(‘userid’)

#querying SQL

user_name =cursor.execute(""“select [First Name], [Emp ID] from [RAW_SAMPLE_ Records] where [Emp ID]={}”"".format(user_id)).fetchone()[0]

date_of_joining =cursor.execute(""“select ([Date of Joining] )from [RAW_SAMPLE_ Records] where [Emp ID]= {}”"".format(user_id)).fetchone()[0]

#setting the output

dispatcher.utter_message(text=(""" Hey {}, your date of joining in kaggle is {} . “”".format(user_name,date_of_joining)))

return []

class GetLeaveBalance(Action):

def name(self):
    return 'get_leave_balance'




def run(self, dispatcher, tracker, domain):
    
    
    #importing librires to connect with wsdl 
    from suds.client import Client
    from suds.sax.element import Element
    
    #specfying the wsdl url and setting the client 
    url = "http://xxxxxxxxxxxx.xxxxxxxxxxxx.in/API/xxxxxxxxxxxxx.svc?wsdl"
    client = Client(url)
    
    #creating the headers for auth in service xml and setting the values for both API-key and API-Code
    Namespace = ('ns2', 'http://xxxxxxxxxxx.com/v1')
    name_space = Element('APICode', ns=Namespace).setText('xxxxxxxxxx')

    Apikey =('ns2',"http://beehivehronline.com/v1")
    api_key = Element('APIKey',ns= Apikey).setText('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ')
    
    client.set_options(soapheaders=(name_space,api_key))
    
    # getting the leave data from GetLeaveBalance for specific user 
    **leave=client.service.GetLeaveBalance("1")**
    leave_data= Client.dict(leave)

##################### Creating list of leave types

    leave_list= tracker.get_slot("leave_type")
    leave_t = leave_list[0]
    
    leave_type=["short_leave", "casual_leave", "sick_leave","earned_leave", "leave_without_pay",
                "paid_leave","paternity_leave","leave"]
    if leave_t in leave_type:
        
        if leave_t == "leave":
            short_l=leave_data['LeaveBalance']["LeaveBalanceData"][0]["Balance"]
            casual_l=leave_data['LeaveBalance']["LeaveBalanceData"][1]["Balance"]
            sick_l=leave_data['LeaveBalance']["LeaveBalanceData"][2]["Balance"]
            earned_l=leave_data['LeaveBalance']["LeaveBalanceData"][3]["Balance"]
            without_pay_l=leave_data['LeaveBalance']["LeaveBalanceData"][4]["Balance"]
            privilege_l=leave_data['LeaveBalance']["LeaveBalanceData"][5]["Balance"]
            Paternity_l=leave_data['LeaveBalance']["LeaveBalanceData"][6]["Balance"]
            
            text_leave=(""" Your Leave balance summary is as follows:
                Short Leave :{}
                Casual Leave : {}
                Sick Leave: {}
                Earned Leave : {}
                Leave Without Pay : {}
                Privilege Leave : {}
                Paternity Leave : {}""".format(short_l,casual_l,sick_l,earned_l,without_pay_l,privilege_l,privilege_l,Paternity_l))
            
         
        
        if leave_t=="short_leave":
              short_l=leave_data['LeaveBalance']["LeaveBalanceData"][0]["Balance"]
              
              text_leave=("""you have {} short leave left""".format(short_l))
              
        if leave_t=="casual_leave":
             casual_l=leave_data['LeaveBalance']["LeaveBalanceData"][1]["Balance"]
             text_leave=("""you have {} casual leave left""".format(casual_l))
             
        if leave_t=="sick_leave":
             sick_l=leave_data['LeaveBalance']["LeaveBalanceData"][2]["Balance"]
             text_leave=("""you have {} sick leave left""".format(sick_l))
             
        if leave_t=="earned_leave":
             earned_l=leave_data['LeaveBalance']["LeaveBalanceData"][3]["Balance"]
             text_leave=("""you have {} earned leave left""".format(earned_l))
             
        if leave_t=="leave_without_pay":
             #without_pay_l=leave_data['LeaveBalance']["LeaveBalanceData"][4]["Balance"]
             text_leave=("""You are limited to have only 30 unplaned leaves in a year""")
             
        if leave_t=="paid_leave":
             privilege_l=leave_data['LeaveBalance']["LeaveBalanceData"][5]["Balance"]
             text_leave=("""you have {} paid leave left""".format(privilege_l))
             
        if leave_t=="paternity_leave":
             Paternity_l=leave_data['LeaveBalance']["LeaveBalanceData"][6]["Balance"]
             text_leave=("""you have {} paternity leave left""".format(Paternity_l))
             
    else:
        
        text_leave=("please enter a valid leave type")

            
        
    dispatcher.utter_message(text_leave)

    return []     
    
    
###################################    
<title>Chat widget</title>

<body>

  <div id="webchat"/>

// Or you can replace latest with a specific version

</body>

################################# socketio: user_message_evt: user_uttered bot_message_evt: bot_uttered

session_persistence: true

rasa: url: “http://localhost:5005/webhook

Regards< Aashay

Yes, How can I do it?