Skip to content

feat: Add AI chatbot with Prism and schedule functionality#40

Merged
naaando merged 18 commits into
mainfrom
feature/chatbot-with-prism
May 6, 2026
Merged

feat: Add AI chatbot with Prism and schedule functionality#40
naaando merged 18 commits into
mainfrom
feature/chatbot-with-prism

Conversation

@naaando
Copy link
Copy Markdown
Owner

@naaando naaando commented May 5, 2026

Summary

  • Upgraded Laravel from v10 to v11 (required for Prism package)
  • Installed echolabsdev/prism package for LLM integration
  • Added OpenRouter provider configuration in config/prism.php
  • Created ChatController with tools for pet and medication management:
    • list_pets - List all user's pets
    • get_pet - Get pet details by name
    • create_pet - Add a new pet
    • list_medications - List medications (optionally filtered by pet)
    • create_medication - Add medication reminder
    • get_upcoming_medications - Show next 24h of reminders
  • Added API endpoints:
    • POST /api/chat - Regular chat response
    • POST /api/chat/stream - Streaming response

Next Steps

  1. Add your OpenRouter API key to .env:
    OPENROUTER_API_KEY=your_key_here
    
  2. Test the chatbot endpoints with an authenticated request

naaando and others added 18 commits May 5, 2026 02:15
- Upgrade Laravel to v11 (required for Prism)
- Install echolabsdev/prism package for LLM integration
- Add OpenRouter provider configuration
- Create ChatController with tools:
  - list_pets, get_pet, create_pet
  - list_medications, create_medication
  - get_upcoming_medications
- Add /api/chat and /api/chat/stream endpoints
- Add user_id to Medicacao fillable to persist user association
- Map species to especie_id when creating pets via LLM tool
- Add whatsapp_accounts table migration and model
- Create EvolutionApiService wrapper for API calls
- Add webhook controller to handle Evolution events:
  - MESSAGES_UPSERT: process incoming messages
  - CONNECTION_UPDATE: track instance status
  - QRCODE_UPDATED: update QR code
- Integrate webhook with Prism chatbot for AI responses
- Add WhatsApp account management endpoints:
  - CRUD operations for instances
  - Refresh QR code, logout, delete
- Add Evolution API config (base_url, key)
- Add routes: /api/webhooks/evolution/{instance}, /api/whatsapp
- Remove account CRUD (managed externally via Evolution panel)
- Add webhook key security (x-webhook-key header)
- Find user by phone number from incoming message
- Add EVOLUTION_SETUP.md with setup instructions
- Simplify connection update handlers (just log, no DB)
- Remove evolution config from services.php
- Inline sendReply method instead of using EvolutionApiService
- Keep only EVOLUTION_WEBHOOK_KEY for webhook security
Multi-stage build with nginx + php-fpm + supervisor, matching the
truckwise deployment pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The composer.lock was generated with PHP 8.4 dependencies
(symfony/filesystem v8.0.9 requires PHP >=8.4).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prism v0.100.1 doesn't have a Transporter enum, causing
package:discover to fail in CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Covers UserController, EspacoController, ChatController, and
EvolutionWebhookController to push coverage above 50%.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Tool::as() is not static in Prism v0.100.1, use (new Tool)->as()
- findUserByPhone now queries WhatsappAccount instead of non-existent
  phone column on users table

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace withOptionalStringParameter() with withStringParameter(required: false)
- Both ChatController and EvolutionWebhookController affected

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Decode JSON body before checking for unicode string content.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Policy tests for Pet and Medicacao
- Model relation tests
- UserObserver test
- Facebook auth integration test
- Google auth route test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- EspacoController store/update tests
- EspacoPolicy unit test
- Webhook processMessage test with Prism fake

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…igration

- Replace $request->validated() with validate()+only() in EspacoController
- Fix whatsapp_accounts migration to use UUID primary key to match HasUuids

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.63959% with 226 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.01%. Comparing base (5a02f39) to head (b810741).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...pi/app/Http/Controllers/Chatbot/ChatController.php 38.50% 99 Missing ⚠️
...Controllers/Webhook/EvolutionWebhookController.php 58.72% 71 Missing ⚠️
...Controllers/Whatsapp/WhatsappAccountController.php 0.00% 56 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
- Coverage   58.33%   56.01%   -2.33%     
==========================================
  Files          40       44       +4     
  Lines         240      632     +392     
==========================================
+ Hits          140      354     +214     
- Misses        100      278     +178     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@naaando naaando merged commit c57e0ca into main May 6, 2026
1 check passed
@naaando naaando deleted the feature/chatbot-with-prism branch May 6, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants