Hello everyone, I am trying to create an on the go button. So I copied one of RasaHQ codes for the same but seem to create an error at dispatcher point. I don’t know what went wrong. Please do help me out.
class Actionstory(Action):
def name(self):
return "action_story_telling"
def run(self, dispatcher, tracker, domain):
try:
is_name=tracker.get_slot('user_name')
if is_name == None or is_name == "":
data = access_db()
is_name = str(data[0])
conn = sqlite3.connect(DB_file_name)
c = conn.cursor()
c.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables=[v[0] for v in c.fetchall() if v[0] != "sqlite_sequence"]
if "user_story" not in tables:
print(1)
c.execute("CREATE TABLE user_story(id integer, name text, story integer)")
c.execute("INSERT INTO user_story VALUES(?, ?,?)",[1, is_name, 1])
id = 1
story = 1
conn.commit()
else:
print(2)
c.execute("SELECT id, story FROM user_story ORDER BY id DESC, story DESC LIMIT 1")
val = c.fetchone()
id = val[0]
story = val[1]
if int(story) == 8:
story = 1
id = id +1
c.execute("INSERT INTO user_story VALUES(?, ?,?)",[id, is_name, story])
conn.commit()
df = pd.read_csv(STORY_file_name)
x = id - 1
y = (story * 2)
listed = df.iat[x,y]
listed = listed.split("&;")
for sent in listed:
dispatcher.utter_message(text=sent)
y = y + 1
pay = df.iat[x,y]
c.execute("SELECT story FROM user_story ORDER BY id DESC, story DESC LIMIT 1")
val = c.fetchone()
story_update = int(val[0]) + 1
c.execute("INSERT INTO user_story VALUES(?, ?,?)",[id, is_name, story_update])
c.execute("SELECT * FROM user_story")
print(c.fetchall())
button = []
button.append({'title': "{}".format(pay), 'payload': '/storying'})
print(button)
conn.commit()
conn.close()
return True
except Error as e:
print(e)
return False
finally:
if conn:
conn.close()
try:
if pay != 'yesno':
dispatcher.utter_message(buttons = button)
except:
traceback.print_exc()
return []
This is the error I am receiveing when I run rasa x in the Rasa run actions terminal. I am sure the problem is dispatcher or the way buttons are formated. Please let me know what’s the issue.
[(1, 'Ashwin', 1), (1, 'Ashwin', 2), (1, 'Ashwin', 3), (1, 'Ashwin', 4), (1, 'Ashwin', 5), (1, 'Ashwin', 6), (1, 'Ashwin', 7), (1, 'Ashwin', 8), (2, 'Ashwin', 1), (2, 'Ashwin', 2), (2, 'Ashwin', 3)]
[{'title': 'hmmm', 'payload': '/storying'}]
Exception occurred while handling uri: 'http://localhost:5055/webhook'
Traceback (most recent call last):
File "/home/ashwinrk/anaconda3/envs/machinelearn/lib/python3.7/site-packages/sanic/app.py", line 976, in handle_request
response = await response
File "/home/ashwinrk/anaconda3/envs/machinelearn/lib/python3.7/site-packages/rasa_sdk/endpoint.py", line 102, in webhook
result = await executor.run(action_call)
File "/home/ashwinrk/anaconda3/envs/machinelearn/lib/python3.7/site-packages/rasa_sdk/executor.py", line 393, in run
validated_events = self.validate_events(events, action_name)
File "/home/ashwinrk/anaconda3/envs/machinelearn/lib/python3.7/site-packages/rasa_sdk/executor.py", line 340, in validate_events
for e in events:
TypeError: 'bool' object is not iterable