Hello Everyone,
@erohmensing @akelad can some one help me with custom actions.py integration over GCP.
I m have deployed one bot using rasa masterclass videos[(Ep #9 - Rasa Masterclass) Improving the assistant: Setting up the Rasa X | Rasa 1.8.0 - YouTube]
I have everything working locally like fetching the result from the google drive api to point out links
My actions.py is as follows :
from future import print_function
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.events import SlotSet
class ActionQuestion(Action):
def name(self) -> Text:
return "action_question"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
dispatcher.utter_message('Found file')
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import logging
logging.getLogger('googleapicliet.discovery_cache').setLevel(logging.ERROR)
SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']
dispatcher.utter_message('Found file')
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('drive', 'v3', credentials=creds)
question = tracker.get_slot("document")
dispatcher.utter_message('Sure, Here it is , please refer below documents for %s . Hope it helps!' %(question))
page_token = None
while True:
response = service.files().list(q='(fullText contains \'{0}\' and name contains \'{0}\')'.format(question, question),
spaces='drive',
fields='nextPageToken, files(id, name)',
pageSize = '1',
pageToken=page_token).execute()
for file in response.get('files', []):
dispatcher.utter_message('Found file: %s please visit the link https://drive.google.com/open?id=%s' % (file.get('name'), file.get('id')))
page_token = response.get('nextPageToken', None)
if page_token is None:
break
return []
‘’’
This code runs normally in local rasa x.
here is screenshot of data being fetched in terminal:
and here is the response in rasa x ui:
I deployed the same code on the RASA GCP and i didnt get custom action response. Although all the intents, slots and actions are correctly predicted
When i removed the logging and google drive api part from actions.py file, like this :
from future import print_function from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.events import SlotSet
class ActionQuestion(Action):
def name(self) -> Text:
return "action_question"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
dispatcher.utter_message('Found file')
return[]
the rasa ui responsed with messafe ‘Found File’.
What could be the issue of not returning the files found.
I have already uploaded the token.pickle file in the /etc/rasa/actions folder.
Also lastly i have tried integrating this bot in the slack, fb, telegram from local using ngrok and succeeded but when i try the same from GCP, responses from rasa to slack or telegram or fb. although message from integrations to rasa ui can be seen in conversations tab with incorrect responses always as action listen.
.i have flagged the conversation. the bot reponse is correct in rasa x ui but not from messengers.
To summarise :
Q1 > how to get the custom integration code work from GCP with various other libraries which may not be present on GCP.
Q2> how to solve the integration issue.
Thanks