All files / api slack.js

0% Statements 0/26
100% Branches 0/0
0% Functions 0/5
0% Lines 0/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67                                                                                                                                     
import { slack } from '../utils/config';
 
const getTimestamp = () => Math.floor(Date.now() / 1000);
 
const makeRequest = payload => {
  const requestHeaders = new Headers();
 
  const requestConfig = {
    method: 'POST',
    headers: requestHeaders,
    body: JSON.stringify(payload)
  };
 
  return slack().then(response => {
    fetch(response.endPoint, requestConfig);
  });
};
 
export const postComment = ({
  userName,
  userEmail,
  comment,
  componentName,
  componentUrl
}) => {
  const payload = {
    username: 'Blabbr',
    attachments: [
      {
        fallback: `${userName} added a new comment to ${componentName}.`,
        color: '#36a64f',
        author_name: `${userName} (${userEmail})`,
        title: `Added a new comment to ${componentName}`,
        title_link: componentUrl,
        text: comment,
        ts: getTimestamp()
      }
    ]
  };
  return makeRequest(payload);
};
 
export const editComment = ({
  userName,
  userEmail,
  comment,
  componentName,
  componentUrl
}) => {
  const payload = {
    username: 'Blabbr',
    attachments: [
      {
        fallback: `${userName} edited their comment on ${componentName}.`,
        color: '#ffcc33',
        author_name: `${userName} (${userEmail})`,
        title: `Edited their comment on ${componentName}`,
        title_link: componentUrl,
        text: comment,
        ts: getTimestamp()
      }
    ]
  };
 
  return makeRequest(payload);
};