Remove phantomjs dependency 🔥
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -41,7 +41,6 @@ gem 'valid_email2'
|
|||||||
gem 'hashie'
|
gem 'hashie'
|
||||||
gem 'chargebee', '~>2'
|
gem 'chargebee', '~>2'
|
||||||
gem 'poltergeist'
|
gem 'poltergeist'
|
||||||
gem 'phantomjs', :require => 'phantomjs/poltergeist'
|
|
||||||
gem 'time_diff'
|
gem 'time_diff'
|
||||||
gem 'bootsnap'
|
gem 'bootsnap'
|
||||||
|
|
||||||
|
|||||||
@@ -281,7 +281,6 @@ GEM
|
|||||||
parser (2.6.4.0)
|
parser (2.6.4.0)
|
||||||
ast (~> 2.4.0)
|
ast (~> 2.4.0)
|
||||||
pg (1.1.4)
|
pg (1.1.4)
|
||||||
phantomjs (2.1.1.0)
|
|
||||||
poltergeist (1.18.1)
|
poltergeist (1.18.1)
|
||||||
capybara (>= 2.1, < 4)
|
capybara (>= 2.1, < 4)
|
||||||
cliver (~> 0.3.1)
|
cliver (~> 0.3.1)
|
||||||
@@ -466,7 +465,6 @@ DEPENDENCIES
|
|||||||
nightfury (~> 1.0, >= 1.0.1)
|
nightfury (~> 1.0, >= 1.0.1)
|
||||||
omniauth-facebook
|
omniauth-facebook
|
||||||
pg
|
pg
|
||||||
phantomjs
|
|
||||||
poltergeist
|
poltergeist
|
||||||
puma (~> 3.0)
|
puma (~> 3.0)
|
||||||
pundit
|
pundit
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class Inbox < ApplicationRecord
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Inbox < ApplicationRecord
|
||||||
validates :account_id, presence: true
|
validates :account_id, presence: true
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
@@ -24,11 +25,11 @@ class Inbox < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def facebook?
|
def facebook?
|
||||||
channel.class.name.to_s == "FacebookPage"
|
channel.class.name.to_s == 'FacebookPage'
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_available_agent
|
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)
|
account.users.find_by(id: user_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -39,17 +40,10 @@ class Inbox < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def round_robin_key
|
def round_robin_key
|
||||||
Constants::RedisKeys::ROUND_ROBIN_AGENTS % { :inbox_id => self.id }
|
Constants::RedisKeys::ROUND_ROBIN_AGENTS % { inbox_id: id }
|
||||||
end
|
end
|
||||||
|
|
||||||
def subscribe_webhook
|
def subscribe_webhook
|
||||||
Facebook::Messenger::Subscriptions.subscribe(access_token: self.channel.page_access_token)
|
Facebook::Messenger::Subscriptions.subscribe(access_token: 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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
66
m.js
66
m.js
@@ -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) }
|
|
||||||
Reference in New Issue
Block a user