Skip to content

Commit 52d4d31

Browse files
authored
Merge pull request RasaHQ#5474 from RasaHQ/muelerma-hangouts-channel
Hangouts Channel integration
2 parents b7590eb + 0bc91a6 commit 52d4d31

File tree

8 files changed

+641
-2
lines changed

8 files changed

+641
-2
lines changed

changelog/5006.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Channel ``hangouts`` for Rasa integration with Google Hangouts Chat is now supported out-of-the-box.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
:desc: Build a Rasa Chat Bot on Google Hangouts Chat
2+
3+
.. _google-hangouts-chat:
4+
5+
Google Hangouts Chat
6+
====================
7+
8+
.. edit-link::
9+
10+
Hangouts Chat Setup
11+
-------------------
12+
13+
This channel works similar to the standard Rasa REST channel. For each request from the channel, your bot will
14+
send one response. The response will be displayed to the user either as text or a so-called card (for
15+
more information, see the Cards section).
16+
17+
In order to connect your Rasa bot to Google Hangouts Chat, you first need to create a project in
18+
Google Developer Console that includes the Hangouts API. There you can specify your bot's endpoint
19+
and also obtain your project id, which determines the scope for the OAuth2 authorization in case you
20+
want to use OAuth2. The Hangouts Chat API sends a Bearer token with every request, but it is up to
21+
the bot to actually verify the token, hence the channel also works without this.
22+
For more information see the official Google resources https://developers.google.com/hangouts/chat.
23+
24+
The possibility to implement asynchronous communication between Hangouts Chat and bot exists, but due
25+
to the usually synchronous nature of Rasa bots, this functionality is not included in this channel.
26+
27+
Running On Hangouts Chat
28+
^^^^^^^^^^^^^^^^^^^^^^^^
29+
30+
If you want to connect to Hangouts Chat using the run script, e.g. using:
31+
32+
.. code-block:: bash
33+
34+
rasa run
35+
36+
you don't need to supply a ``credentials.yml``.
37+
38+
If you want to use OAuth2, simply put the project id obtained from the Google Developer Console into it.
39+
40+
.. code-block:: yaml
41+
42+
hangouts:
43+
project_id: "12345678901"
44+
45+
The endpoint for receiving Hangouts Chat messages is
46+
``http://localhost:5005/webhooks/hangouts/webhook``, replacing
47+
the host and port with the appropriate values. Hangouts Chat only forwards
48+
messages to endpoints via ``https``, so take appropriate measures to add
49+
it to your setup.
50+
51+
52+
Cards and Interactive Cards
53+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
55+
There are two ways in which Hangouts Chat will display bot messages, either as text or card. For each recevied
56+
request, your bot will send all messages in one response. If one of those messages is a card (e.g. an image),
57+
all other messages are converted to card format as well.
58+
59+
Interactive cards trigger the ``CARD_CLICKED`` event for user interactions, e.g. when a button is clicked. When
60+
creating an interactive card, e.g. via ``dispatcher.utter_button_message()`` in your ``actions.py``, you can
61+
specify a payload for each button that is going to be returned with the ``CARD_CLICKED`` event and extracted
62+
by the ``HangoutsInput`` channel (for example
63+
``buttons=[{"text":"Yes!", "payload":"/affirm"}, {"text":"Nope.", "payload":"/deny"}])``.
64+
Updating cards is not yet supported.
65+
66+
For more detailed information on cards, visit the
67+
`Hangouts docs <https://developers.google.com/hangouts/chat/reference>`_.
68+
69+
70+
Other Hangouts Chat Events
71+
^^^^^^^^^^^^^^^^^^^^^^^^^^
72+
73+
Except for ``MESSAGE`` and ``CARD_CLICKED``, Hangouts Chat knows two other event types, ``ADDED_TO_SPACE`` and
74+
``REMOVED_FROM_SPACE``, which are triggered when your bot is added or removed from a direct message or chat room
75+
space. The default intent names for these events can be modified in the ``HangoutsInput`` constructor method.

docs/user-guide/messaging-and-voice-channels.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Learn how to make your assistant available on:
3737
connectors/cisco-webex-teams
3838
connectors/rocketchat
3939
connectors/mattermost
40+
connectors/hangouts
4041
connectors/custom-connectors
4142

4243

poetry.lock

Lines changed: 32 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ tensorflow-probability = "~0.7"
122122
setuptools = ">=41.0.0"
123123
kafka-python = "^1.4"
124124
ujson = "^1.35"
125+
oauth2client = "4.1.3"
125126

126127
[tool.poetry.dev-dependencies]
127128
pytest-cov = "^2.8.1"

rasa/core/channels/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from rasa.core.channels.telegram import TelegramInput # nopep8
2626
from rasa.core.channels.twilio import TwilioInput # nopep8
2727
from rasa.core.channels.webexteams import WebexTeamsInput # nopep8
28+
from rasa.core.channels.hangouts import HangoutsInput # nopep8
2829

2930
input_channel_classes = [
3031
CmdlineInput,
@@ -40,6 +41,7 @@
4041
RestInput,
4142
SocketIOInput,
4243
WebexTeamsInput,
44+
HangoutsInput,
4345
] # type: List[InputChannel]
4446

4547
# Mapping from a input channel name to its class to allow name based lookup.

0 commit comments

Comments
 (0)