Skip to content
endofline edited this page Aug 9, 2015 · 5 revisions

A Google Script sink can be configured for users to send message from Google Scripts directly to group conversations or user one-to-ones.

configuring and starting the sink

  1. Generate a .pem file

  2. Edit your config.json file and add the following entry into the jsonrpc key:

     "jsonrpc": [
       {
         "certfile": "/root/server.pem",
         "module": "sinks.google.scripts.webhookReceiver",
         "name": "<SERVER IP>",
         "port": <PORT NUMBER>
       }
     ]
    
  3. (Re-)start the bot

testing the sink

You can use the mockgoogle-send.py script to test your sink first before proceeding to the actual setup and configuration on Google Scripts.

usage: mockgoogle-send.py [-h] url
positional arguments:
  url         url to send the data
optional arguments:
  -h, --help  show this help message and exit

The url should resemble the following format:

https://<SERVER IP>:<PORT NUMBER>/<CONV ID>
or
https://<SERVER IP>:<PORT NUMBER>/<USER ID>

configuring Google Scripts

  1. Open up Google Scripts and paste the following:

    function sendToHangupsBot(conv_id, message) {
      // Replace the address with the address and port to your server
      var serveraddress = '<SERVER IP>:<PORT NUMBER>';
    
      var url = 'https://' + serveraddress + '/' + conv_id + '/';
      var options = {
        'method': 'post',
        'contentType': 'application/json; charset=utf-8',
        'validateHttpsCertificates': false,
        'payload': '{"message":"'+message+'"}'
      };
    
      UrlFetchApp.fetch(url, options);
    }
  2. When you need to send a message to a particular hangout, call sendToHangupsBot() with conv_id as the name of the conversation (use /bot whereami to find that out within hangouts) and message as the message that you'd like to send.

# ## ###

Clone this wiki locally