Initial public release

This commit is contained in:
William Entriken 2021-08-16 23:08:19 -04:00
parent 7e93d61b42
commit ad64b76158
6 changed files with 163 additions and 2 deletions

View file

@ -0,0 +1,45 @@
<?php

namespace Modules\SidebarWebhook\Providers;
use Illuminate\Support\ServiceProvider;

define('MODULE_SA', 'sidebarwebhook');

class SidebarWebhookServiceProvider extends ServiceProvider
{
public function boot()
{
// Behaviors documented at https://nwidart.com/laravel-modules/v6/advanced-tools/module-resources
$this->registerViews();
$this->hooks();
}

public function hooks()
{
\Eventy::addAction('conversation.after_prev_convs', function($customer, $conversation, $mailbox) {
$webhookUri = 'https://example.com/';
$customerEmail = $customer->getMainEmail();
if (empty($customerEmail)) {
return;
}
echo \View::make('sidebarwebhook::partials/sidebar', [
'customerEmail' => $customerEmail,
'url' => $webhookUri,
])->render();
}, 10, 3);
}
public function registerViews()
{
$viewPath = resource_path('views/modules/sidebarwebhook');
$sourcePath = __DIR__ . '/../Resources/views';

$this->publishes([
$sourcePath => $viewPath
], 'views');

$this->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/sidebarwebhook';
}, \Config::get('view.paths')), [$sourcePath]), 'sidebarwebhook');
}
}

View file

@ -1,2 +1,61 @@
# freescout-sidebar-webhook
Sidebar Webhook asynchronously injects HTML from your server into conversation sidebars
# FreeScout Sidebar Webhook
Sidebar Webhook asynchronously injects HTML from your server into conversation sidebars.

This screenshot shows what it does: you can load any content, on a per-customer basis from your own web server, asynchronously, every time a conversation is loaded on the screen.

![screenshot](/Users/williamentriken/Developer/freescout-sidebar-webhook/screenshot.png)

## Use cases

- Directly link to your customer management system
- Show details about order status live from your fulfillment system
- Quickly ship changes to your FreeScout system UI without updating modules
- Connect to backends using PHP/Node.js/Ruby/Perl/Rust/Go/Bash/Haskell and even Java

## Installation

These instructions assume you installed FreeScout using the [recommended process](https://github.com/freescout-helpdesk/freescout/wiki/Installation-Guide), the "one-click install" or the "interactive installation bash-script", and you are viewing this page using a macOS or Ubuntu system.

Other installations are possible, but those are not supported here.

1. Download the [latest release of FreeScout Sidebar Webhook](https://github.com/fulldecent/freescout-sidebar-webhook/releases).

2. Unzip the file locally.

3. Open SidebarWebhookServiceProvider.php using a code editor and change the value of `$webhookUri` to be your endpoint's secret URL.

4. Copy the folder into your server using SFTP.

```sh
scp -r ~/Desktop/freescout-sidebar-webhook root@freescout.examplec.com:/var/www/html/Modules/SidebarWebhook/
```

5. Access your admin modules page like https://freescout.example.com/modules/list.

5. Find **Sidebar Webhook** and click ACTIVATE.
6. Purchase a license code by sending USD 10 at https://www.paypal.com/paypalme/fulldecent/10usd

## Your webhook server

Your webhook server will receive requests of type `application/x-www-form-urlencoded` (in PHP, access with `$_POST`...) and including the data like:

```json
{
"_token": "osnuthensuhtnoehu2398g3",
"customerEmail": "hello@example.com"
}
```

Your response will be a partial HTML document which is directly injected into the sidebar.

## Project scope

Our goal is to have a very simple module to allow vast extensibility in the conversation sidebar.

Anything that makes it simpler (removes unneded code) or more extensible for most people (adding a couple post parameters in `hooks()`) will be a welcome improvement.

At this point, it is a non-goal to add friendly configuration of the webhook URI or other configuration options.

## Inspiration

* This project was inspired by [Sidebar API]([Sidebar API Scoutdevs](https://scoutdevs.com/downloads/sidebar-api/)).

View file

@ -0,0 +1,21 @@
<div class="conv-sidebar-block" id="swh-content">
<img src="{{ asset('img/loader-tiny.gif') }}"/>
</div>
@section('javascript')
@parent
const ajaxUrl = "{{ $url }}";
const customerEmail = "{{ $customerEmail }}";

$(document).ready(function(){
$.ajax({
url: ajaxUrl,
type: "post",
data: {
"_token": "{{ csrf_token() }}",
customerEmail: customerEmail
}
}).done(function(html) {
$("#swh-content").html(html);
});
});
@endsection

24
composer.json Normal file
View file

@ -0,0 +1,24 @@
{
"name": "fulldecent/freescout-sidebar-webhook",
"description": "",
"authors": [
{
"name": "William Entriken",
"email": "github.com@phor.net"
}
],
"extra": {
"laravel": {
"providers": [
"Modules\\SidebarWebhook\\Providers\\SidebarWebhookServiceProvider"
],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"Modules\\SidebarWebhook\\": ""
}
}
}

12
module.json Normal file
View file

@ -0,0 +1,12 @@
{
"name": "Sidebar Webhook",
"alias": "sidebarwebhook",
"description": "Sidebar Webhook asynchronously injects HTML from your server into conversation sidebars.",
"version": "1.0.0",
"detailsUrl": "https://github.com/fulldecent/freescout-sidebar-webhook",
"author": "William Entriken",
"providers": [
"Modules\\SidebarWebhook\\Providers\\SidebarWebhookServiceProvider"
],
"requires": []
}

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB