Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Change] use project_id from json, instead of credentials #460

Merged
merged 2 commits into from Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions dialogflow_task_executive/README.md
Expand Up @@ -52,6 +52,8 @@ Or we can use `credential` and `project_id` arguments of ` dialogflow_task_execu
roslaunch dialogflow_task_executive dialogflow_task_executive.launch credential:=/etc/ros/hogehoge.json project_id:=pr2-hogehoge
```

If you have `project_id` in both your credential file and rospram (or argument of `dialogflow_task_executive.launch`), the `project_id` in both your credential file becomes effective. To use `project_id` in rosparam, use `~override_project_id` option.

## How to register new task in Dialogflow

### Create new `app_manager` app
Expand Down
2 changes: 2 additions & 0 deletions dialogflow_task_executive/launch/dialogflow_ros.launch
Expand Up @@ -7,6 +7,7 @@
<arg name="volume" default="1.0" />
<arg name="credential" default="$(optenv GOOGLE_APPLICATION_CREDENTIALS false)" doc="Read credentials JSON from this value when use_yaml is false." />
<arg name="project_id" default="$(optenv DIALOGFLOW_PROJECT_ID false)"/>
<arg name="override_project_id" default="false" doc="Specify true if the project_id argument takes priority over the project_id section of the credential file." />
<arg name="enable_hotword" default="true" />
<arg name="always_publish_result" default="false" doc="Always publish dialog_response topic even the node gets actionlib request." />

Expand All @@ -20,6 +21,7 @@
soundplay_action_name: $(arg soundplay_action_name)
volume: $(arg volume)
project_id: $(arg project_id)
override_project_id: $(arg override_project_id)
google_cloud_credentials_json: $(arg credential)
enable_hotword: $(arg enable_hotword)
always_publish_result: $(arg always_publish_result)
Expand Down
Expand Up @@ -3,6 +3,7 @@
<arg name="applist" default="$(find dialogflow_task_executive)/apps"/>
<arg name="credential" default="$(optenv GOOGLE_APPLICATION_CREDENTIALS false)" doc="Read credentials JSON from this value when use_yaml is false." />
<arg name="project_id" default="$(optenv DIALOGFLOW_PROJECT_ID false)"/>
<arg name="override_project_id" default="false" doc="Specify true if the project_id argument takes priority over the project_id section of the credential file." />
<arg name="enable_hotword" default="true" />
<arg name="always_publish_result" default="false" doc="Always publish dialog_response topic even the node gets actionlib request." />

Expand All @@ -29,6 +30,7 @@
<arg name="volume" value="$(arg volume)" />
<arg name="credential" value="$(arg credential)" />
<arg name="project_id" value="$(arg project_id)" />
<arg name="override_project_id" value="$(arg override_project_id)" />
<arg name="enable_hotword" value="$(arg enable_hotword)" />
<arg name="always_publish_result" value="$(arg always_publish_result)" />
</include>
Expand Down
11 changes: 9 additions & 2 deletions dialogflow_task_executive/node_scripts/dialogflow_client.py
Expand Up @@ -83,11 +83,18 @@ def __init__(self):
credentials_json
)
self.project_id = credentials.project_id
if rospy.has_param("~project_id") and rospy.get_param("~override_project_id", False):
self.project_id = rospy.get_param("~project_id")
rospy.logwarn("override project_id")
rospy.logwarn(" from : project_id in a credential file {}".format(credentials.project_id))
rospy.logwarn(" to : project_id stored in rosparam {}".format(self.project_id))
self.session_client = df.SessionsClient(
credentials=credentials
)
if self.project_id is None:
rospy.logerr('project ID is not set')
else:
rospy.loginfo('project ID is "{}"'.format(self.project_id))
self.pub_res = rospy.Publisher(
"dialog_response", DialogResponse, queue_size=1)
self.always_publish_result = rospy.get_param(
Expand Down Expand Up @@ -139,7 +146,7 @@ def cb(self, goal):
if self.session_id is None:
self.session_id = str(uuid.uuid1())
rospy.loginfo(
"Created new session: {}".format(self.session_id))
"DialogflowTextClient: Created new session: {}".format(self.session_id))
session = self.session_client.session_path(
self.project_id, self.session_id
)
Expand Down Expand Up @@ -292,7 +299,7 @@ def df_run(self):
if self.session_id is None:
self.session_id = str(uuid.uuid1())
rospy.loginfo(
"Created new session: {}".format(self.session_id))
"DialogflowAudioClient: Created new session: {}".format(self.session_id))
session = self.session_client.session_path(
self.project_id, self.session_id)

Expand Down