|
| 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. |
0 commit comments