nico
(Nico Link)
October 1, 2018, 2:20pm
1
Hi,
return [SlotSet(“sgcontract”, sgcontract)] wont work for me even though I can check that sgcontract actually has a value. Why could this be?
Is there another way of setting slots, because this one is not really working.
What I am basically trying to do is: I am getting some data out of mySQL database. I want to fill this data into some slots for the bot to use at a later time.
Thanks in advance,
Nico
akelad
(Akela Drissner)
October 2, 2018, 9:04am
2
Can you post your stories and full custom action?
nico
(Nico Link)
October 2, 2018, 12:05pm
3
Story associated with the custom action:
##TESTO
* greet
- action_noname
* mood_great
- utter_happy
* retrieve_infos
- action_calldatabase
* afirm
- utter_upgradeconfirm
Custom Action:
def read(client,dispatcher, tracker):
PhoneNumber = ""
Name = ""
contract = ""
end_date = ""
datausage = ""
callusage = ""
smsusage = ""
sgupgrade = ""
sgcontract = ""
sgcontractinfo = ""
db = pymysql.connect( host = '127.0.0.1', port = 3306, user = 'root', passwd = 'XXXXXX', db = 'XXXXXXX')
cursor = db.cursor()
sql = "SELECT * FROM clients WHERE PhoneNumber = %s"
ph = tracker.get_slot('PhoneNumber')
try:
cursor.execute(sql, (ph,))
results = cursor.fetchall()
for row in results:
PhoneNumber = row[0]
Name = row[1]
contract = row[2]
end_date = row[3]
sgupgrade = row[4]
sgcontract = row[5]
sgcontractinfo = row[6]
datausage = row[7]
callusage = row[8]
smsusage = row[9]
except:
print("Error fetching data.")
finally:
print(cursor.execute(sql, (ph,)))
print(results)
print(sgcontract)
db.close()
dispatcher.utter_template("utter_databasecall", tracker, PhoneNumber= PhoneNumber, Name = Name, contract= contract, date= end_date)
dispatcher.utter_template("utter_upsale", tracker, Name = Name, contract= contract, date= end_date, sgupgrade = sgupgrade, sgcontract = sgcontract)
result = [SlotSet("PhoneNumber", PhoneNumber ), SlotSet("Name", Name ), SlotSet("contract", contract ), SlotSet("end_date", end_date ), SlotSet("datausage", datausage ), SlotSet("callusage", callusage ), SlotSet("smsusage", smsusage ), SlotSet("sgupgrade", sgupgrade ), SlotSet("sgcontract", sgcontract ), SlotSet("sgcontractinfo", sgcontractinfo )]
return result
akelad
(Akela Drissner)
October 4, 2018, 4:38pm
4
This should be in the run()
method of your custom action
1 Like