text: // Twilio Test
  const config = require('dotenv').config();
  const accountSid = process.env.TWILIO_ACCOUNT_SID;
  const authToken = process.env.TWILIO_AUTH_TOKEN;
  const notifyServiceSid = process.env.NOTIFY_SERVICE_SID;
  const phone_number = process.env.PHONE_NUMBER;
  
  const client = require('twilio')(accountSid, authToken);
  
  function sendMessage(tweet) {
    client.notify.services(notifyServiceSid) 
    .notifications.create({
      toBinding: JSON.stringify({
          binding_type: 'sms', address: phone_number
      }),
      body: tweet
    })
    .then(notification => console.log(notification.sid))
    .catch(error => console.log(error));
  }
  
  // Twitter
  const http = require('http')
  const path = require('path')
  const express = require('express')
  const socketIo = require('socket.io')
  const needle = require('needle')
  const TOKEN = process.env.TWITTER_BEARER_TOKEN
  const PORT = process.env.PORT || 3000
  
  const app = express()
  
  const server = http.createServer(app)
  const io = socketIo(server)
  
  // CSS FIX
  app.use(express.static(path.join(__dirname, 'public')));
  
  
  app.get('/', (req, res) => {
    res.sendFile(path.resolve(__dirname, '../', 'client', 'index.html'))
  })
  
  const rulesURL = 'https://api.twitter.com/2/tweets/search/stream/rules'
  const streamURL =
    'https://api.twitter.com/2/tweets/search/stream?tweet.fields=public_metrics&expansions=author_id'
  
  const rules = [{ "value":"(from:MarquardtA OR from:IAPonomarenko OR from:KyivIndependent OR from:UkraineUpdates3)" }]
  
  // Get stream rules
  async function getRules() {
    const response = await needle('get', rulesURL, {
      headers: {
        Authorization: `Bearer ${TOKEN}`,
      },
    })
    console.log(response.body.text)
    return response.body
  }
  
  // Set stream rules
  async function setRules() {
    const data = {
      add: rules,
    }
  
    const response = await needle('post', rulesURL, data, {
      headers: {
        'content-type': 'application/json',
        Authorization: `Bearer ${TOKEN}`,
      },
    })
  
    return response.body
  }
  
  // Delete stream rules
  async function deleteRules(rules) {
    if (!Array.isArray(rules.data)) {
      return null
    }
  
    const ids = rules.data.map((rule) => rule.id)
  
    const data = {
      delete: {
        ids: ids,
      },
    }
  
    const response = await needle('post', rulesURL, data, {
      headers: {
        'content-type': 'application/json',
        Authorization: `Bearer ${TOKEN}`,
      },
    })
  
    return response.body
  }
  
  function streamTweets(socket) {
    const stream = needle.get(streamURL, {
      headers: {
        Authorization: `Bearer ${TOKEN}`,
      },
    })
  
    stream.on('data', (data) => {
      try {
        const json = JSON.parse(data)
        console.log(json)
        //console.log(json.data.text)
        socket.emit('tweet', json)
        //console.log(JSON.stringify(data.text))
        //sendMessage(JSON.stringify(data.text))
        sendMessage(json.data.text)
      } catch (error) {}
    })
  
    return stream
  }
  
  io.on('connection', async () => {
    console.log('Client connected...')
  
    let currentRules
  
    try {
      //   Get all stream rules
      currentRules = await getRules()
  
      // Delete all stream rules
      await deleteRules(currentRules)
  
      // Set rules based on array above
      await setRules()
    } catch (error) {
      console.error(error)
      process.exit(1)
    }
  
    const filteredStream = streamTweets(io)
  
    let timeout = 0
    filteredStream.on('timeout', () => {
      // Reconnect on error
      console.warn('A connection error occurred. Reconnecting…')
      setTimeout(() => {
        timeout++
        streamTweets(io)
      }, 2 ** timeout)
      streamTweets(io)
    })
  })
  
  server.listen(PORT, () => console.log(`Listening on port ${PORT}`))