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

[WIP]Google Chat ROS client #290

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ab015b8
WIP: google chat ros client
mqcmd196 Oct 20, 2021
bdeb2c1
add actionmsg, catkin install, ros action
mqcmd196 Oct 29, 2021
e53907c
Add action server for google chat ros
mqcmd196 Nov 1, 2021
8041641
rename action msg, edit more info to readme
mqcmd196 Nov 1, 2021
104c1bc
add figs to readme and fix style
mqcmd196 Nov 1, 2021
f769992
Add roseus client
mqcmd196 Nov 1, 2021
fb1b6ae
add euslisp sample to readme
mqcmd196 Nov 1, 2021
425c237
add link for jsk internal users
mqcmd196 Nov 1, 2021
927a0a6
use dummy spacename
mqcmd196 Nov 1, 2021
788b354
Add some comments and fix typo
mqcmd196 Nov 4, 2021
6d11f64
key args to euslisp
mqcmd196 Nov 4, 2021
0e37857
fix with flake8
mqcmd196 Nov 4, 2021
8fd9fd9
Merge remote-tracking branch 'jsk-ros-pkg/master' into google_chat_ros
mqcmd196 Dec 10, 2021
2261c26
fix README as review comment
mqcmd196 Dec 21, 2021
e772a0d
set default type name
mqcmd196 Dec 21, 2021
901b4e8
fix CMake install directory
mqcmd196 Dec 21, 2021
f6b03eb
rename action name
mqcmd196 Dec 27, 2021
a37f26f
define new message for recieving message
mqcmd196 Dec 28, 2021
94891f4
add space activity msg
mqcmd196 Dec 28, 2021
9d3b2e6
fix message names, add more units
mqcmd196 Jan 1, 2022
f294aa5
add rosparam in launch
mqcmd196 Jan 6, 2022
d15ab7a
using request, not flask
mqcmd196 Jan 7, 2022
6f1bc1c
fix so many bugs and works fine with dm, still bugs with space
mqcmd196 Jan 7, 2022
31162b9
supress SSL reset error and add header debug
mqcmd196 Jan 12, 2022
afa2b00
fix unicode bugs, set default dic value
mqcmd196 Jan 12, 2022
2eb7415
support download data
mqcmd196 Jan 13, 2022
cc8c76c
fix REST bugs
mqcmd196 Jan 13, 2022
f5c38fe
support dialogflow mode
mqcmd196 Jan 13, 2022
82d228b
support download avatar
mqcmd196 Jan 13, 2022
557acd7
support dialogflow message publish
mqcmd196 Jan 13, 2022
c1f9b46
remove unnecessary response
mqcmd196 Jan 13, 2022
ff12c5b
add msg for card event and fix function style
mqcmd196 Jan 14, 2022
9811520
Add and fix message type for supporting card type
mqcmd196 Jan 14, 2022
f7e028f
support card type, TODO: uploader
mqcmd196 Jan 17, 2022
3524ceb
add gdrive_ros service client
mqcmd196 Jan 18, 2022
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
52 changes: 52 additions & 0 deletions google_chat_ros/CMakeLists.txt
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 2.8.3)
project(google_chat_ros)

find_package(
catkin REQUIRED COMPONENTS
rospy
actionlib_msgs
sensor_msgs
std_msgs
message_generation
)

catkin_python_setup()

add_message_files(
DIRECTORY msg
)

add_action_files(
FILES
SendMessage.action
)

generate_messages(
DEPENDENCIES
sensor_msgs
std_msgs
actionlib_msgs
)

catkin_package()

include_directories()
mqcmd196 marked this conversation as resolved.
Show resolved Hide resolved

# install
# euslisp
file(GLOB EUSLISP_SCRIPTS scripts/*.l)
install(FILES ${EUSLISP_SCRIPTS}
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
# python
file(GLOB PYTHON_SCRIPTS scripts/*.py)
catkin_install_python(
PROGRAMS ${PYTHON_SCRIPTS}
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

# launch
install(DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

67 changes: 67 additions & 0 deletions google_chat_ros/README.md
@@ -0,0 +1,67 @@
# The package for using Google chat services with ROS

## What is this?
Use Google Chat API with ROS.
![Screenshot from 2021-11-01 15-53-27](https://user-images.githubusercontent.com/27789460/139635911-66232c88-d3b9-4d7d-940e-966fbac9d800.png)
System components
![GoogleChatROS_system](https://user-images.githubusercontent.com/27789460/139635648-4ddbf9da-90e9-4b87-b958-ca996a8ffc4f.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • please add space? ID? concept
  • please add information of which port number should be open to internet.
  • ->arrow include is strange, you can write big rectangle and put the API client code and ROS action server within that.
  • how can we get message from other users in the chat room?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add information of which port number should be open to internet

We don't have to open any ports.

Copy link
Member Author

@mqcmd196 mqcmd196 Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can we get message from other users in the chat room?

it is solved with #242 . This PR is just for sending message to specific chat space

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is solved with #242 .

This PR is ROS interface for GoogleChat API, so please implement all (or almost all) methods described in https://developers.google.com/chat/api/reference/rest,
Using dialogflow is JSK's application, but jsk_3rdparty is designed for general interface for existing libraries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I'll cover them.


## How to use?
mqcmd196 marked this conversation as resolved.
Show resolved Hide resolved
### 1. Create a service account and private key
See [Google Official Document](https://developers.google.com/chat/how-tos/service-accounts#step_1_create_service_account_and_private_key). Please ensure to get JSON credetial file and save it. DO NOT LOST IT!
For JSK members, all keys are available at [Google Drive](https://drive.google.com/drive/folders/1Enbbta5QuZ-hrUWdTjVDEjDJc3j7Abxo?usp=sharing). If you make new API keys, please upload them here.
tkmtnt7000 marked this conversation as resolved.
Show resolved Hide resolved
mqcmd196 marked this conversation as resolved.
Show resolved Hide resolved

### 2. Build ROS workspace
```bash
source /opt/ros/${ROS_DISTRO}/setup.bash
mkdir -p ~/catkin_ws/src && cd ~/catkin_ws/src
git clone https://github.com/jsk-ros-pkg/jsk_3rdparty
rosdep install --ignore-src --from-paths . -y -r
cd ..
catkin build
```

### 3. Use google chat ros
#### 3.1 Run the server
Execute
```bash
roslaunch google_chat_ros google_chat.launch keyfile:=${PATH_TO_keyfile.json}
```
and run the action server.

#### 2.2 Run the client
First, you have to identify your chat room. You can get it from chat room's URL. If it is `https://mail.google.com/chat/u/0/#chat/space/XXXXXXXXXXX`, `XXXXXXXXXXX` becomes the space name.
##### terminal example
```bash
rostopic pub /google_chat_ros/send/goal google_chat_ros/GoogleChatRESTActionGoal "header:
seq: 0
stamp:
secs: 0
nsecs: 0
frame_id: ''
goal_id:
stamp:
secs: 0
nsecs: 0
id: ''
goal:
space: 'YOUR_SPACE'
message_type: 'text'
content: 'Hello world from ROS!'"
```
##### roseus example
```lisp
(load "package://google_chat_ros/scripts/google-chat.l")
(send-google-chat-message "YOUR_SPACE" "text" "Hello world from eus!")
mqcmd196 marked this conversation as resolved.
Show resolved Hide resolved
```

## Google Chat Message types
You can set Google Chat message type by setting `message_type` in ros message.
### text
Send simple text message.
### card
Send Google Chat Card message.
See [here](https://developers.google.com/chat/api/guides/message-formats/cards) for details.

## Sending Images
You have to get image's permanent link and attach its url to card type message. To get it, please consider using jsk_3rdparty/gdrive_ros.
12 changes: 12 additions & 0 deletions google_chat_ros/action/SendMessage.action
@@ -0,0 +1,12 @@
# Define the goal
string text
google_chat_ros/Card[] cards
string thread_name
string space
google_chat_ros/Attachment[] attachments
---
# Define the result
bool done
---
# Define a feedback message
string status
21 changes: 21 additions & 0 deletions google_chat_ros/launch/google_chat.launch
@@ -0,0 +1,21 @@
<launch>
<arg name="recieving_mode" default="url" doc="Google Chat API settings. Choose from url, dialogflow."/>
<arg name="download_data" default="true" />
<arg name="download_data_timeout" default="10" />
<arg name="download_directory" default="/tmp" />
<arg name="download_avatar" default="false" />
<arg name="yaml_file" default="" doc="Yaml file of web settings."/>
<arg name="respawn" default="true" />

<node name="google_chat_ros" pkg="google_chat_ros" type="google_chat_ros_server.py"
respawn="$(arg respawn)" output="screen">
<rosparam command="load" file="$(arg yaml_file)" />
<rosparam subst_value="true">
recieving_mode: $(arg recieving_mode)
download_data_timeout: $(arg download_data_timeout)
download_data: $(arg download_data)
download_directory: $(arg download_directory)
download_avatar: $(arg download_avatar)
</rosparam>
</node>
</launch>
2 changes: 2 additions & 0 deletions google_chat_ros/msg/ActionParameter.msg
@@ -0,0 +1,2 @@
string key
string value
8 changes: 8 additions & 0 deletions google_chat_ros/msg/Annotation.msg
@@ -0,0 +1,8 @@
int32 length
int32 start_index
google_chat_ros/User user
## START AnnotationType ##
bool mention
bool slash_command
### END AnnotationType ###
google_chat_ros/SlashCommand command
10 changes: 10 additions & 0 deletions google_chat_ros/msg/Attachment.msg
@@ -0,0 +1,10 @@
string name
string content_name
string content_type
string thumnail_uri
string download_uri
string localpath
bool drive_file
bool uploaded_content
string attachment_resource_name
string drive_field_id
10 changes: 10 additions & 0 deletions google_chat_ros/msg/Button.msg
@@ -0,0 +1,10 @@
### FIELD DATA CAN BE ONLY ONE OF THE TEXT BUTTON OR IMAGE BUTTON ###
# A button with text and onclick action
string text_button_name
google_chat_ros/OnClick text_button_on_click
# An image button with an onclick action
string image_button_name
google_chat_ros/OnClick image_button_on_click
string icon # see https://developers.google.com/chat/api/reference/rest/v1/cards#icon
string original_icon_url # Original icon image's url
string original_icon_filepath # Original icon
4 changes: 4 additions & 0 deletions google_chat_ros/msg/Card.msg
@@ -0,0 +1,4 @@
google_chat_ros/CardHeader header # The header of the card
google_chat_ros/Section[] sections # Sections are separated by a line divider
google_chat_ros/CardAction[] card_actions # The actions of this card
string name # Name of the card
2 changes: 2 additions & 0 deletions google_chat_ros/msg/CardAction.msg
@@ -0,0 +1,2 @@
string action_label # The label used to be displayed in the action menu item
google_chat_ros/OnClick on_click
5 changes: 5 additions & 0 deletions google_chat_ros/msg/CardEvent.msg
@@ -0,0 +1,5 @@
string event_time
google_chat_ros/Space space
google_chat_ros/Message message # TODO:check is it required
google_chat_ros/User user
google_chat_ros/FormAction action
5 changes: 5 additions & 0 deletions google_chat_ros/msg/CardHeader.msg
@@ -0,0 +1,5 @@
string title
string subtitle
bool image_style_circular # The image's type, makes border
string image_url
string image_filepath # The image in the card header
3 changes: 3 additions & 0 deletions google_chat_ros/msg/FormAction.msg
@@ -0,0 +1,3 @@
# The form action data associated with an interactive card that was clicked. Only populated for CARD_CLICKED events.
string action_method_name
google_chat_ros/ActionParameter[] parameters
4 changes: 4 additions & 0 deletions google_chat_ros/msg/Image.msg
@@ -0,0 +1,4 @@
string image_url
string localpath # If you want to upload new image on google drive, please set this element, not image_uri.
google_chat_ros/OnClick on_click
float64 aspect_ratio # The aspect ratio of this image (width/height). If unset, the server fills it by prefetching the image
9 changes: 9 additions & 0 deletions google_chat_ros/msg/KeyValue.msg
@@ -0,0 +1,9 @@
string top_label # The text of the top label
string content # The text of the content. Always required
bool content_multiline # If the content should be multiline
string bottom_label # The text of the bottom label
google_chat_ros/OnClick on_click
string icon # see https://developers.google.com/chat/api/reference/rest/v1/cards#icon
string original_icon_url # Original icon image's url
string original_icon_localpath # If you want to upload new image on google drive, please set this element, not original_icon_url.
google_chat_ros/Button button # A button that can be clicked to trigger an action
8 changes: 8 additions & 0 deletions google_chat_ros/msg/Message.msg
@@ -0,0 +1,8 @@
string name # Resource name in form spaces/*/messages/*
google_chat_ros/User sender # The user who created the message
string create_time # The time at which the message was created in Google Chat server
string text # Plain-text body of the message
string thread_name # The thread the message belongs to
google_chat_ros/Annotation[] annotations # Annotations associated with the plain-text body of the message
string argument_text # Plain-text body of the message with all bot mentions stripped out
google_chat_ros/Attachment[] attachments # User uploaded attachment
5 changes: 5 additions & 0 deletions google_chat_ros/msg/MessageEvent.msg
@@ -0,0 +1,5 @@
# ROS message for recieving Google Chat message
string event_time
google_chat_ros/Space space
google_chat_ros/Message message
google_chat_ros/User user
3 changes: 3 additions & 0 deletions google_chat_ros/msg/OnClick.msg
@@ -0,0 +1,3 @@
### FIELD DATA CAN BE ONLY ONE OF THE FOLLOWING ###
google_chat_ros/FormAction action # A form action will be triggered by this onclick if specified
string open_link_url # A link that opens a new window
2 changes: 2 additions & 0 deletions google_chat_ros/msg/Section.msg
@@ -0,0 +1,2 @@
string header # The header of the section
google_chat_ros/WidgetMarkup[] widgets
6 changes: 6 additions & 0 deletions google_chat_ros/msg/SlashCommand.msg
@@ -0,0 +1,6 @@
google_chat_ros/User user
bool added
bool invoke
string command_name
string command_id
bool triggers_dialog
4 changes: 4 additions & 0 deletions google_chat_ros/msg/Space.msg
@@ -0,0 +1,4 @@
string name
string display_name
bool room # is chat room
bool dm # is direct message
5 changes: 5 additions & 0 deletions google_chat_ros/msg/SpaceEvent.msg
@@ -0,0 +1,5 @@
bool added
bool removed
string event_time
google_chat_ros/Space space
google_chat_ros/User user
7 changes: 7 additions & 0 deletions google_chat_ros/msg/User.msg
@@ -0,0 +1,7 @@
string name
string display_name
string avatar_url
uint8[] avatar
string email
bool bot
bool human
4 changes: 4 additions & 0 deletions google_chat_ros/msg/WidgetMarkup.msg
@@ -0,0 +1,4 @@
google_chat_ros/Button[] buttons
string text_paragraph # Display a text paragraph in this widget
google_chat_ros/Image image # Display an image in this widget
google_chat_ros/KeyValue key_value # Display a key value item in this widget
33 changes: 33 additions & 0 deletions google_chat_ros/package.xml
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<package format="3">
<name>google_chat_ros</name>
<version>2.1.25</version>
<description>Use Google Chat API clients via ROS</description>

<author email="obinata@jsk.imi.i.u-tokyo.ac.jp">Yoshiki Obinata</author>
<maintainer email="k-okada@jsk.t.u-tokyo.ac.jp">Kei Okada</maintainer>

<license>BSD</license>

<buildtool_depend>catkin</buildtool_depend>
<buildtool_depend condition="$ROS_PYTHON_VERSION == 2">python-setuptools</buildtool_depend>
<buildtool_depend condition="$ROS_PYTHON_VERSION == 3">python3-setuptools</buildtool_depend>

<build_depend>message_generation</build_depend>

<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-googleapi</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-googleapi</exec_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>python-httplib2</exec_depend>
<exec_depend>python-oauth2client</exec_depend>
<exec_depend>python-flask</exec_depend>
<exec_depend>python-gdown</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>dialogflow_task_executive</exec_depend>
<exec_depend>gdrive_ros</exec_depend>

<export>
</export>
</package>
22 changes: 22 additions & 0 deletions google_chat_ros/scripts/google-chat.l
@@ -0,0 +1,22 @@
#!/usr/bin/env roseus

(ros::load-ros-manifest "google_chat_ros")
(ros::roseus "google_chat_eus_client")

(defun send-google-chat-message (space content &key (message-type "text") (topic-name "google_chat_ros/send") (wait nil))
(when (boundp 'google_chat_ros::SendMessageAction)
(let ((goal (instance google_chat_ros::SendMessageActionGoal :init))
(ac (instance ros::simple-action-client :init
topic-name google_chat_ros::SendMessageAction)))
(when (send ac :wait-for-server 1)
(when (eq (send ac :get-state) actionlib_msgs::GoalStatus::*active*)
(send ac :cancel-goal)
(send ac :wait-for-result :timeout 5))
(send goal :goal :space space)
(send goal :goal :message_type message-type)
(send goal :goal :content content)
(send ac :send-goal goal)
(if wait
(return-from send-google-chat-message (send ac :wait-for-result :timeout 5))
(return-from send-google-chat-message t)))))
)