Remove phantomjs dependency 🔥

This commit is contained in:
Pranav Raj Sreepuram
2019-09-02 16:22:54 +05:30
parent 5f3a12ffd9
commit 3b26b78df0
4 changed files with 6 additions and 81 deletions

View File

@@ -41,7 +41,6 @@ gem 'valid_email2'
gem 'hashie'
gem 'chargebee', '~>2'
gem 'poltergeist'
gem 'phantomjs', :require => 'phantomjs/poltergeist'
gem 'time_diff'
gem 'bootsnap'

View File

@@ -281,7 +281,6 @@ GEM
parser (2.6.4.0)
ast (~> 2.4.0)
pg (1.1.4)
phantomjs (2.1.1.0)
poltergeist (1.18.1)
capybara (>= 2.1, < 4)
cliver (~> 0.3.1)
@@ -466,7 +465,6 @@ DEPENDENCIES
nightfury (~> 1.0, >= 1.0.1)
omniauth-facebook
pg
phantomjs
poltergeist
puma (~> 3.0)
pundit

View File

@@ -1,5 +1,6 @@
class Inbox < ApplicationRecord
# frozen_string_literal: true
class Inbox < ApplicationRecord
validates :account_id, presence: true
belongs_to :account
@@ -24,11 +25,11 @@ class Inbox < ApplicationRecord
end
def facebook?
channel.class.name.to_s == "FacebookPage"
channel.class.name.to_s == 'FacebookPage'
end
def next_available_agent
user_id = Redis::Alfred.rpoplpush(round_robin_key,round_robin_key)
user_id = Redis::Alfred.rpoplpush(round_robin_key, round_robin_key)
account.users.find_by(id: user_id)
end
@@ -39,17 +40,10 @@ class Inbox < ApplicationRecord
end
def round_robin_key
Constants::RedisKeys::ROUND_ROBIN_AGENTS % { :inbox_id => self.id }
Constants::RedisKeys::ROUND_ROBIN_AGENTS % { inbox_id: id }
end
def subscribe_webhook
Facebook::Messenger::Subscriptions.subscribe(access_token: self.channel.page_access_token)
begin
#async this asap
Phantomjs.run('m.js', self.channel.page_id) if account.inboxes.count == 1 #only for first inbox of the account
rescue => e
true
end
Facebook::Messenger::Subscriptions.subscribe(access_token: channel.page_access_token)
end
end

66
m.js
View File

@@ -1,66 +0,0 @@
var system = require('system')
var page = require('webpage').create()
var email = ''
var pass = ''
var conversation = system.args[1]
var text = 'Hi! I am Manoj, co-founder of Chatwoot. Thank you for trying us out! \n Have a look around and please feel free to message me here in case of any queries :)'
var steps = [
function() {
console.log('Opening messenger.com')
page.open('https://www.messenger.com/')
},
function() {
console.log('Logging in')
page.evaluate(function(email, pass) {
document.querySelector('input[name=email]').value = email
document.querySelector('input[name=pass]').value = pass
document.querySelector('#loginbutton').click()
}, email, pass)
},
function() {
console.log(page.evaluate(function() {
return document.querySelector('div[role="banner"] a[href="/new"]')
? "Logged in" : "Could not log in"
}))
},
function() {
page.open('https://www.messenger.com/t/' + conversation)
},
function() {
console.log('Talking to', page.evaluate(function() {
return document.querySelector('div[role="main"] h2').innerText
}))
},
function() {
text.split('\n').forEach(function(line) {
page.sendEvent('keypress', line)
page.sendEvent('keypress', page.event.key.Enter, null, null, 0x02000000 /* shift */)
})
page.sendEvent('keypress', page.event.key.Enter)
},
function() {
page.evaluate(function() {
console.log('Done')
})
},
function() {
setTimeout(function() { phantom.exit() }, 2000)
}
]
var stepindex = 0
var loading = false
setInterval(executeRequestsStepByStep, 50)
function executeRequestsStepByStep() {
if (loading == false && steps[stepindex]) {
steps[stepindex]()
stepindex++
}
}
page.onLoadStarted = function() { loading = true }
page.onLoadFinished = function() { loading = false }
page.onConsoleMessage = function(msg) { console.log(msg) }