title: How to send firebase data to slack using cloud functions?
body: <p>I cloned this sample <a href="https://github.com/firebase/functions-samples/tree/master/minimal-webhook" rel="nofollow noreferrer">minimal-webhook</a> and got this working. I wanted to extend this functionality by sending the writes to slack. </p>
  
  <p>I am using the incoming webhook of slack. I guess the issue is the way how I add the data payload in nodejs. Can anyone help? Thanks in advance. Attached my code and error log from firebase.</p>
  
  <pre><code>const functions = require('firebase-functions');
  const request = require('request-promise');
  const WEBHOOK_URL = 'https://hooks.slack.com/services/abc'
  var headers = {
      'Content-type': 'application/json'
  };
  exports.webhook = functions.database.ref('/hooks/{hookId}').onWrite(event =&gt; {
    return request({
      uri: WEBHOOK_URL,
      method: 'POST',
      headers: headers,
       body: event.data.toJSON,
      resolveWithFullResponse: true
    }).then(response =&gt; {
      if (response.statusCode &gt;= 400) {
        throw new Error(`HTTP Error: ${response.statusCode}`);
      }
      console.log('SUCCESS! Posted', event.data.ref);
    });
  });`
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/BZSjN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BZSjN.png" alt="Also attached the error log from Firebase"></a></p>