-
Notifications
You must be signed in to change notification settings - Fork 42
Add Chatwoot plugin and provider #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Chatwoot Widget (by Boy132) | ||
|
|
||
| Adds a Chatwoot live chat widget to all panels for real-time customer support. | ||
|
|
||
| ## Features | ||
|
|
||
| - Chatwoot live chat integration | ||
| - Configurable through plugin settings | ||
|
|
||
| ## Credits | ||
|
|
||
| Original Tawk.to widget by Boy132. Edited by Philip E to work with Chatwoot. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'base_url' => env('CHATWOOT_BASE_URL'), | ||
| 'website_token' => env('CHATWOOT_WEBSITE_TOKEN'), | ||
| ]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "id": "chatwoot", | ||
| "name": "Chatwoot", | ||
| "author": "Boy132 (edited by Philip E)", | ||
| "version": "1.0.0", | ||
| "description": "Adds a Chatwoot widget to all panels", | ||
| "category": "plugin", | ||
| "url": "https://github.com/pelican-dev/plugins/tree/main/chatwoot", | ||
| "update_url": null, | ||
| "namespace": "Boy132\\Chatwoot", | ||
| "class": "ChatwootPlugin", | ||
| "panels": null, | ||
| "panel_version": null, | ||
| "composer_packages": null | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| namespace Boy132\Chatwoot; | ||
|
|
||
| use App\Contracts\Plugins\HasPluginSettings; | ||
| use App\Traits\EnvironmentWriterTrait; | ||
| use Filament\Contracts\Plugin; | ||
| use Filament\Forms\Components\TextInput; | ||
| use Filament\Notifications\Notification; | ||
| use Filament\Panel; | ||
|
|
||
| class ChatwootPlugin implements HasPluginSettings, Plugin { | ||
| use EnvironmentWriterTrait; | ||
|
|
||
| public function getId(): string { | ||
| return 'chatwoot'; | ||
| } | ||
|
|
||
| public function register(Panel $panel): void {} | ||
|
|
||
| public function boot(Panel $panel): void {} | ||
|
|
||
| public function getSettingsForm(): array { | ||
| return [ | ||
| TextInput::make('base_url') | ||
| ->label('Base URL') | ||
| ->required() | ||
| ->default(fn () => config('chatwoot.base_url')), | ||
| TextInput::make('website_token') | ||
| ->label('Website Token') | ||
| ->required() | ||
| ->default(fn () => config('chatwoot.website_token')), | ||
| ]; | ||
| } | ||
|
|
||
| public function saveSettings(array $data): void { | ||
| $this->writeToEnvironment([ | ||
| 'CHATWOOT_BASE_URL' => $data['base_url'], | ||
| 'CHATWOOT_WEBSITE_TOKEN' => $data['website_token'], | ||
| ]); | ||
|
|
||
| Notification::make() | ||
| ->title('Settings saved') | ||
| ->success() | ||
| ->send(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||
| <?php | ||||||||||||||
|
|
||||||||||||||
| namespace Boy132\Chatwoot\Providers; | ||||||||||||||
|
|
||||||||||||||
| use Filament\Support\Facades\FilamentView; | ||||||||||||||
| use Filament\View\PanelsRenderHook; | ||||||||||||||
| use Illuminate\Support\Facades\Blade; | ||||||||||||||
| use Illuminate\Support\ServiceProvider; | ||||||||||||||
|
|
||||||||||||||
| class ChatwootPluginProvider extends ServiceProvider { | ||||||||||||||
| public function boot(): void { | ||||||||||||||
|
Comment on lines
+10
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix Pint style: opening braces must be on their own line. The Lint pipeline is failing ( 🎨 Proposed fix-class ChatwootPluginProvider extends ServiceProvider {
- public function boot(): void {
+class ChatwootPluginProvider extends ServiceProvider
+{
+ public function boot(): void
+ {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| $baseUrl = config('chatwoot.base_url'); | ||||||||||||||
| $websiteToken = config('chatwoot.website_token'); | ||||||||||||||
|
|
||||||||||||||
| if ($baseUrl && $websiteToken) { | ||||||||||||||
| FilamentView::registerRenderHook( | ||||||||||||||
| PanelsRenderHook::STYLES_BEFORE, | ||||||||||||||
| fn () => Blade::render(<<<'HTML' | ||||||||||||||
| <!--Start of Chatwoot Script--> | ||||||||||||||
| <script type="text/javascript"> | ||||||||||||||
| (function(d,t) { | ||||||||||||||
| var BASE_URL="{{ $baseUrl }}"; | ||||||||||||||
| var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; | ||||||||||||||
| g.src=BASE_URL+"/packs/js/sdk.js"; | ||||||||||||||
| g.defer = true; | ||||||||||||||
| g.async = true; | ||||||||||||||
| s.parentNode.insertBefore(g,s); | ||||||||||||||
| g.onload=function(){ | ||||||||||||||
| window.chatwootSDK.run({ | ||||||||||||||
| websiteToken: '{{ $websiteToken }}', | ||||||||||||||
| baseUrl: BASE_URL | ||||||||||||||
| }) | ||||||||||||||
| } | ||||||||||||||
| })(document,"script"); | ||||||||||||||
| </script> | ||||||||||||||
| <!--End of Chatwoot Script--> | ||||||||||||||
| HTML, [ | ||||||||||||||
| 'baseUrl' => $baseUrl, | ||||||||||||||
| 'websiteToken' => $websiteToken, | ||||||||||||||
| ]) | ||||||||||||||
|
Comment on lines
+18
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: The Laravel Blade Js::from helper, part of Illuminate\Support\Js, safely embeds PHP values into JavaScript by converting them to properly escaped JavaScript expressions. It handles objects and arrays by base64-encoding JSON and wrapping in JSON.parse(atob('...')), strings with single quotes and escapes, and other types via json_encode. Use it in Blade templates as {{ Js::from($value) }} or {{ \Illuminate\Support\Js::from($value) }}. Example: <script> var app = {{ Js::from($array) }}; </script> This ensures safe inclusion within HTML attributes or scripts, preventing XSS from unescaped JSON. Recent Laravel versions (e.g., 13.x) include a Js facade alias for convenience. There's also an undocumented Citations:
JS-escape interpolated values in the injected
🔒 Proposed fix using
|
||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix Pint style: opening braces on their own line for class and all methods.
The Lint pipeline is failing (
class_definition,braces_position,single_class_elements). Move every{on theclass/method signature lines to the next line.🎨 Proposed fix
🧰 Tools
🪛 PHPMD (2.15.0)
[warning] 19-19: Avoid unused parameters such as '$panel'. (undefined)
(UnusedFormalParameter)
[warning] 21-21: Avoid unused parameters such as '$panel'. (undefined)
(UnusedFormalParameter)
🤖 Prompt for AI Agents