evolution(helpscout.webhooks): mise en place des rappel web afin de notifier l'equipe tech des bug identifies par le support
Co-authored-by: Colin Darie <colin@darie.eu>
This commit is contained in:
parent
6d68c581af
commit
a1dbc40f57
6 changed files with 373 additions and 6 deletions
|
@ -1,7 +1,15 @@
|
||||||
class WebhookController < ActionController::Base
|
class WebhookController < ActionController::Base
|
||||||
before_action :verify_signature!, only: :helpscout
|
before_action :verify_signature!
|
||||||
skip_before_action :verify_authenticity_token
|
skip_before_action :verify_authenticity_token
|
||||||
|
|
||||||
|
def helpscout_support_dev
|
||||||
|
if tagged_dev? && status_active?
|
||||||
|
send_mattermost_notification(message_to_mattermost_channel)
|
||||||
|
end
|
||||||
|
|
||||||
|
head :no_content
|
||||||
|
end
|
||||||
|
|
||||||
def helpscout
|
def helpscout
|
||||||
email = params[:customer][:email].downcase
|
email = params[:customer][:email].downcase
|
||||||
user = User.find_by(email: email)
|
user = User.find_by(email: email)
|
||||||
|
@ -34,6 +42,38 @@ class WebhookController < ActionController::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def send_mattermost_notification(text)
|
||||||
|
return if Rails.application.secrets.dig(:mattermost, :support_webhook_url).blank?
|
||||||
|
|
||||||
|
Net::HTTP.post(
|
||||||
|
URI.parse(Rails.application.secrets.mattermost[:support_webhook_url]),
|
||||||
|
{ "text": text }.to_json,
|
||||||
|
"Content-Type" => "application/json"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_to_mattermost_channel
|
||||||
|
%Q(
|
||||||
|
Nouveau bug taggué #dev : https://secure.helpscout.net/conversation/#{params["id"]}/#{params["number"]}?folderId=#{params["folderId"]}
|
||||||
|
|
||||||
|
> #{params['webhook']['preview']}
|
||||||
|
|
||||||
|
**personnes impliquées** : #{threads.map { |thread| thread['createdBy']['email'] }.uniq.join(", ")}
|
||||||
|
**utilisateur en attente depuis** : #{params['customerWaitingSince']['friendly']})
|
||||||
|
end
|
||||||
|
|
||||||
|
def threads
|
||||||
|
params['_embedded']['threads']
|
||||||
|
end
|
||||||
|
|
||||||
|
def tagged_dev?
|
||||||
|
params["tags"].any? { _1['tag'].include?('dev') }
|
||||||
|
end
|
||||||
|
|
||||||
|
def status_active?
|
||||||
|
params["status"] == 'active'
|
||||||
|
end
|
||||||
|
|
||||||
def link_to_manager(model, url)
|
def link_to_manager(model, url)
|
||||||
"<a target='_blank' href='#{url}' rel='noopener'>#{model.model_name.human}##{model.id}</a>"
|
"<a target='_blank' href='#{url}' rel='noopener'>#{model.model_name.human}##{model.id}</a>"
|
||||||
end
|
end
|
||||||
|
|
|
@ -155,3 +155,6 @@ SAML_IDP_SECRET_KEY="-----BEGIN RSA PRIVATE KEY-----\nblabla+blabla\n-----END RS
|
||||||
SAML_DOLIST_CERTIFICATE="spcertificate"
|
SAML_DOLIST_CERTIFICATE="spcertificate"
|
||||||
SAML_DOLIST_HOST="dolisthoname"
|
SAML_DOLIST_HOST="dolisthoname"
|
||||||
DOLIST_LOGIN_URL="https://clientpreprod.dolist.net"
|
DOLIST_LOGIN_URL="https://clientpreprod.dolist.net"
|
||||||
|
|
||||||
|
# pour des rappel web
|
||||||
|
SUPPORT_WEBHOOK_URL=""
|
||||||
|
|
|
@ -183,6 +183,7 @@ Rails.application.routes.draw do
|
||||||
get "contact-admin", to: "support#admin"
|
get "contact-admin", to: "support#admin"
|
||||||
|
|
||||||
post "webhooks/helpscout", to: "webhook#helpscout"
|
post "webhooks/helpscout", to: "webhook#helpscout"
|
||||||
|
post "webhooks/helpscout_support_dev", to: "webhook#helpscout_support_dev"
|
||||||
match "webhooks/helpscout", to: lambda { |_| [204, {}, nil] }, via: :head
|
match "webhooks/helpscout", to: lambda { |_| [204, {}, nil] }, via: :head
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -58,6 +58,8 @@ defaults: &defaults
|
||||||
client_key: <%= ENV['SENDINBLUE_CLIENT_KEY'] %>
|
client_key: <%= ENV['SENDINBLUE_CLIENT_KEY'] %>
|
||||||
smtp_key: <%= ENV['SENDINBLUE_SMTP_KEY'] %>
|
smtp_key: <%= ENV['SENDINBLUE_SMTP_KEY'] %>
|
||||||
api_v3_key: <%= ENV['SENDINBLUE_API_V3_KEY'] %>
|
api_v3_key: <%= ENV['SENDINBLUE_API_V3_KEY'] %>
|
||||||
|
mattermost:
|
||||||
|
support_webhook_url: <%= ENV['SUPPORT_WEBHOOK_URL'] %>
|
||||||
matomo:
|
matomo:
|
||||||
cookie_domain: "<%= ENV['MATOMO_COOKIE_DOMAIN'] %>"
|
cookie_domain: "<%= ENV['MATOMO_COOKIE_DOMAIN'] %>"
|
||||||
domain: "<%= ENV['MATOMO_DOMAIN'] %>"
|
domain: "<%= ENV['MATOMO_DOMAIN'] %>"
|
||||||
|
|
|
@ -1,10 +1,21 @@
|
||||||
describe WebhookController, type: :controller do
|
describe WebhookController, type: :controller do
|
||||||
describe '#helpscout' do
|
before do
|
||||||
before do
|
allow(controller).to receive(:verify_signature!).and_return(true)
|
||||||
allow(controller).to receive(:verify_signature!).and_return(true)
|
allow(controller).to receive(:verify_authenticity_token)
|
||||||
allow(controller).to receive(:verify_authenticity_token)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
describe '#helpscout_support_dev' do
|
||||||
|
subject(:response) { post :helpscout_support_dev, params: payload }
|
||||||
|
let(:payload) { JSON.parse(File.read(Rails.root.join('spec', 'fixtures', 'files', 'helpscout', 'tagged-dev.json'))) }
|
||||||
|
|
||||||
|
it 'works' do
|
||||||
|
allow(Rails.application.secrets).to receive(:dig).with(:mattermost, :support_webhook_url).and_return("https://notification_url")
|
||||||
|
expect(controller).to receive(:send_mattermost_notification).with("\nNouveau bug taggué #dev : https://secure.helpscout.net/conversation/123456789/123456789?folderId=123456789\n\n> Bonjour, Je voudrais faire une demande de changement d'adresse et la plateforme m'indique que j'ai plusieurs comptes et que je dois d'abord les fusionner. Cela fait 3 jours que j'essaie de fusio\n\n**personnes impliquées** : anonymous@anon.fr\n**utilisateur en attente depuis** : 11 min ago")
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#helpscout' do
|
||||||
subject(:response) { get :helpscout, params: { customer: { email: customer_email } } }
|
subject(:response) { get :helpscout, params: { customer: { email: customer_email } } }
|
||||||
|
|
||||||
let(:payload) { JSON.parse(subject.body) }
|
let(:payload) { JSON.parse(subject.body) }
|
||||||
|
|
310
spec/fixtures/files/helpscout/tagged-dev.json
vendored
Normal file
310
spec/fixtures/files/helpscout/tagged-dev.json
vendored
Normal file
|
@ -0,0 +1,310 @@
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"number":123456789,
|
||||||
|
"threads":123456789,
|
||||||
|
"type":"email",
|
||||||
|
"folderId":123456789,
|
||||||
|
"status":"active",
|
||||||
|
"state":"published",
|
||||||
|
"subject":"Fusionner plusieurs comptes existants",
|
||||||
|
"preview":"Bonjour, Je voudrais faire une demande de changement d'adresse et la plateforme m'indique que j'ai plusieurs comptes et que je dois d'abord les fusionner. Cela fait 3 jours que j'essaie de fusio",
|
||||||
|
"mailboxId":123456789,
|
||||||
|
"createdBy":{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"customer",
|
||||||
|
"first":"",
|
||||||
|
"last":"",
|
||||||
|
"photoUrl":"https://photo.png",
|
||||||
|
"email":"anonymous.fr"
|
||||||
|
},
|
||||||
|
"createdAt":"2022-11-03T10:05:59Z",
|
||||||
|
"closedBy":123456789,
|
||||||
|
"closedByUser":{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"user",
|
||||||
|
"first":"unknown",
|
||||||
|
"last":"unknown",
|
||||||
|
"email":"unknown"
|
||||||
|
},
|
||||||
|
"userUpdatedAt":"2022-11-03T10:05:59Z",
|
||||||
|
"customerWaitingSince":{
|
||||||
|
"time":"2022-11-03T10:05:59Z",
|
||||||
|
"friendly":"11 min ago"
|
||||||
|
},
|
||||||
|
"source":{
|
||||||
|
"type":"api",
|
||||||
|
"via":"customer"
|
||||||
|
},
|
||||||
|
"tags":[
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"color":"#A5B2BD",
|
||||||
|
"tag":"contact form"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"color":"#A5B2BD",
|
||||||
|
"tag":"dev"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"color":"#A5B2BD",
|
||||||
|
"tag":"other"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cc":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"bcc":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"primaryCustomer":{
|
||||||
|
"id":"lol",
|
||||||
|
"type":"customer",
|
||||||
|
"first":"",
|
||||||
|
"last":"",
|
||||||
|
"photoUrl":"https://photo.png",
|
||||||
|
"email":"anonymous@anon.fr"
|
||||||
|
},
|
||||||
|
"customFields":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"_embedded":{
|
||||||
|
"threads":[
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"customer",
|
||||||
|
"status":"active",
|
||||||
|
"state":"published",
|
||||||
|
"action":{
|
||||||
|
"type":"default",
|
||||||
|
"associatedEntities":[
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body":"Bonjour,\n\u003cbr\u003e\n\u003cbr\u003eJe voudrais faire une demande de changement d'adresse et la plateforme m'indique que j'ai plusieurs comptes et que je dois d'abord les fusionner.\n\u003cbr\u003e\n\u003cbr\u003eCela fait 3 jours que j'essaie de fusionner les soit disant comptes sans succès.\n\u003cbr\u003e\n\u003cbr\u003eMerci m'apporter votre aide.\n\u003cbr\u003e\n\u003cbr\u003eCordialement,",
|
||||||
|
"source":{
|
||||||
|
"type":"api",
|
||||||
|
"via":"customer"
|
||||||
|
},
|
||||||
|
"customer":{
|
||||||
|
"id":123456789,
|
||||||
|
"first":"",
|
||||||
|
"last":"",
|
||||||
|
"photoUrl":"https://photo.png",
|
||||||
|
"email":"anonymous@anon.fr"
|
||||||
|
},
|
||||||
|
"createdBy":{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"customer",
|
||||||
|
"first":"",
|
||||||
|
"last":"",
|
||||||
|
"photoUrl":"https://photo.png",
|
||||||
|
"email":"anonymous@anon.fr"
|
||||||
|
},
|
||||||
|
"to":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"cc":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"bcc":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"createdAt":"2022-11-03T10:05:59Z",
|
||||||
|
"_embedded":{
|
||||||
|
"attachments":[
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"_links":{
|
||||||
|
"createdByCustomer":{
|
||||||
|
"href":"https://api.helpscout.net/v2/customers/576939812"
|
||||||
|
},
|
||||||
|
"customer":{
|
||||||
|
"href":"https://api.helpscout.net/v2/customers/576939812"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"_links":{
|
||||||
|
"self":{
|
||||||
|
"href":"https://api.helpscout.net/v2/conversations/2056713321"
|
||||||
|
},
|
||||||
|
"mailbox":{
|
||||||
|
"href":"https://api.helpscout.net/v2/mailboxes/125926"
|
||||||
|
},
|
||||||
|
"primaryCustomer":{
|
||||||
|
"href":"https://api.helpscout.net/v2/customers/576939812"
|
||||||
|
},
|
||||||
|
"createdByCustomer":{
|
||||||
|
"href":"https://api.helpscout.net/v2/customers/576939812"
|
||||||
|
},
|
||||||
|
"closedBy":{
|
||||||
|
"href":"https://api.helpscout.net/v2/users/0"
|
||||||
|
},
|
||||||
|
"threads":{
|
||||||
|
"href":"https://api.helpscout.net/v2/conversations/2056713321/threads/"
|
||||||
|
},
|
||||||
|
"web":{
|
||||||
|
"href":"https://secure.helpscout.net/conversation/2056713321/1995582"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"controller":"webhook",
|
||||||
|
"action":"helpscout_support_dev",
|
||||||
|
"webhook":{
|
||||||
|
"id":123456789,
|
||||||
|
"number":123456789,
|
||||||
|
"threads":123456789,
|
||||||
|
"type":"email",
|
||||||
|
"folderId":123456789,
|
||||||
|
"status":"active",
|
||||||
|
"state":"published",
|
||||||
|
"subject":"Fusionner plusieurs comptes existants",
|
||||||
|
"preview":"Bonjour, Je voudrais faire une demande de changement d'adresse et la plateforme m'indique que j'ai plusieurs comptes et que je dois d'abord les fusionner. Cela fait 3 jours que j'essaie de fusio",
|
||||||
|
"mailboxId":123456789,
|
||||||
|
"createdBy":{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"customer",
|
||||||
|
"first":"",
|
||||||
|
"last":"",
|
||||||
|
"photoUrl":"https://photo.png",
|
||||||
|
"email":"anonymous@anon.fr"
|
||||||
|
},
|
||||||
|
"createdAt":"2022-11-03T10:05:59Z",
|
||||||
|
"closedBy":123456789,
|
||||||
|
"closedByUser":{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"user",
|
||||||
|
"first":"unknown",
|
||||||
|
"last":"unknown",
|
||||||
|
"email":"unknown"
|
||||||
|
},
|
||||||
|
"userUpdatedAt":"2022-11-03T10:05:59Z",
|
||||||
|
"customerWaitingSince":{
|
||||||
|
"time":"2022-11-03T10:05:59Z",
|
||||||
|
"friendly":"11 min ago"
|
||||||
|
},
|
||||||
|
"source":{
|
||||||
|
"type":"api",
|
||||||
|
"via":"customer"
|
||||||
|
},
|
||||||
|
"tags":[
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"color":"#A5B2BD",
|
||||||
|
"tag":"contact form"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"color":"#A5B2BD",
|
||||||
|
"tag":"dev"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"color":"#A5B2BD",
|
||||||
|
"tag":"other"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cc":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"bcc":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"primaryCustomer":{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"customer",
|
||||||
|
"first":"",
|
||||||
|
"last":"",
|
||||||
|
"photoUrl":"https://photo.png",
|
||||||
|
"email":"anonymous@anon.fr"
|
||||||
|
},
|
||||||
|
"customFields":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"_embedded":{
|
||||||
|
"threads":[
|
||||||
|
{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"customer",
|
||||||
|
"status":"active",
|
||||||
|
"state":"published",
|
||||||
|
"action":{
|
||||||
|
"type":"default",
|
||||||
|
"associatedEntities":[
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body":"Bonjour,\n\u003cbr\u003e\n\u003cbr\u003eJe voudrais faire une demande de changement d'adresse et la plateforme m'indique que j'ai plusieurs comptes et que je dois d'abord les fusionner.\n\u003cbr\u003e\n\u003cbr\u003eCela fait 3 jours que j'essaie de fusionner les soit disant comptes sans succès.\n\u003cbr\u003e\n\u003cbr\u003eMerci m'apporter votre aide.\n\u003cbr\u003e\n\u003cbr\u003eCordialement,",
|
||||||
|
"source":{
|
||||||
|
"type":"api",
|
||||||
|
"via":"customer"
|
||||||
|
},
|
||||||
|
"customer":{
|
||||||
|
"id":123456789,
|
||||||
|
"first":"",
|
||||||
|
"last":"",
|
||||||
|
"photoUrl":"https://photo.png",
|
||||||
|
"email":"anonymous@anon.fr"
|
||||||
|
},
|
||||||
|
"createdBy":{
|
||||||
|
"id":123456789,
|
||||||
|
"type":"customer",
|
||||||
|
"first":"",
|
||||||
|
"last":"",
|
||||||
|
"photoUrl":"https://photo.png",
|
||||||
|
"email":"anonymous@anon.fr"
|
||||||
|
},
|
||||||
|
"to":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"cc":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"bcc":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"createdAt":"2022-11-03T10:05:59Z",
|
||||||
|
"_embedded":{
|
||||||
|
"attachments":[
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"_links":{
|
||||||
|
"createdByCustomer":{
|
||||||
|
"href":"https://api.helpscout.net/v2/customers/576939812"
|
||||||
|
},
|
||||||
|
"customer":{
|
||||||
|
"href":"https://api.helpscout.net/v2/customers/576939812"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"_links":{
|
||||||
|
"self":{
|
||||||
|
"href":"https://api.helpscout.net/v2/conversations/xxx"
|
||||||
|
},
|
||||||
|
"mailbox":{
|
||||||
|
"href":"https://api.helpscout.net/v2/mailboxes/xxx"
|
||||||
|
},
|
||||||
|
"primaryCustomer":{
|
||||||
|
"href":"https://api.helpscout.net/v2/customers/xxx"
|
||||||
|
},
|
||||||
|
"createdByCustomer":{
|
||||||
|
"href":"https://api.helpscout.net/v2/customers/xxx"
|
||||||
|
},
|
||||||
|
"closedBy":{
|
||||||
|
"href":"https://api.helpscout.net/v2/users/0"
|
||||||
|
},
|
||||||
|
"threads":{
|
||||||
|
"href":"https://api.helpscout.net/v2/conversations/xxx/threads/"
|
||||||
|
},
|
||||||
|
"web":{
|
||||||
|
"href":"https://secure.helpscout.net/conversation/xxx/xxx"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue