Skip to content

Commit 3db62fc

Browse files
author
exatasmente
committed
Update Botman Whatsapp driver
1 parent 31385cb commit 3db62fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2323
-759
lines changed

Procfile

100644100755
File mode changed.

README.md

100644100755
File mode changed.

app/Conversations/Boasvindas.php

+30-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Conversations;
44

55
use App\Jobs\GeraAtendimento;
6-
use App\Models\Formulario;
76
use BotMan\BotMan\Messages\Conversations\Conversation;
87
use BotMan\BotMan\Messages\Incoming\Answer;
98
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
@@ -17,7 +16,7 @@ class Boasvindas extends Conversation
1716
protected $campo;
1817
protected $respostas ;
1918

20-
public function __construct($formulario)
19+
public function __construct($formulario)
2120
{
2221
$this->formulario = $formulario;
2322

@@ -39,10 +38,10 @@ public function pegaResposta($valido = null){
3938
if($validator->fails()){
4039
return $this->pegaResposta(false);
4140
}
42-
$this->email = $resposta->getText();
41+
$email = $resposta->getText();
4342

44-
$this->ask('Qual motivo para o seu contato conosco?',function(Answer $resposta){
45-
GeraAtendimento::dispatch($this->respostas,$this->email,$resposta->getText());
43+
$this->ask('Qual motivo para o seu contato conosco?',function(Answer $resposta) use($email){
44+
GeraAtendimento::dispatch($this->respostas,$email,$resposta->getText());
4645
});
4746
$this->say('Suas informações foram cadastradas com sucesso!');
4847

@@ -113,20 +112,34 @@ public function pegaResposta($valido = null){
113112

114113
public function resposta(Answer $resposta){
115114
$valido = true;
116-
$validator = Validator::make([Str::slug($this->campo->nome) => $resposta->getText()], [
117-
Str::slug($this->campo->nome) => $this->campo->validacao,
118-
119-
]);
115+
$opcao = null;
120116

121-
if($validator->fails()){
122-
$valido =false;
123-
}
124-
$this->respostas []= [
125-
'formulario_id' => $this->formulario->id,
126-
'campo_id' => $this->campo->id,
127-
'resposta' => $resposta->getText()
128-
];
117+
if($this->campo->tipo > 1 and $this->campo->tipo < 5){
118+
$opcao = collect($this->campo->opcoesArray())->where('valor',$resposta->getText())->first();
119+
if($opcao === null){
120+
$valido = false;
121+
}else{
122+
$opcao = $opcao->nome;
123+
}
124+
}else {
125+
$validator = Validator::make([Str::slug($this->campo->nome) => $resposta->getText()], [
126+
Str::slug($this->campo->nome) => $this->campo->validacao,
127+
128+
]);
129+
if ($validator->fails()) {
130+
$valido = false;
131+
}else{
132+
$opcao = $resposta->getText();
133+
}
129134

135+
}
136+
if($valido == true) {
137+
$this->respostas [] = [
138+
'formulario_id' => $this->formulario->id,
139+
'campo_id' => $this->campo->id,
140+
'resposta' => $opcao
141+
];
142+
}
130143
return $this->pegaResposta($valido);
131144
}
132145
public function run()

app/Conversations/ExampleConversation.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
<?php
22

33
namespace App\Conversations;
4-
use Illuminate\Support\Facades\Log;
54
use App\Jobs\NotificaPsicologo;
65
use App\Models\Formulario;
7-
use App\Notifications\NotificaPsicologos;
86
use App\Models\User;
9-
use Illuminate\Foundation\Inspiring;
7+
use BotMan\BotMan\Messages\Conversations\Conversation;
108
use BotMan\BotMan\Messages\Incoming\Answer;
11-
use BotMan\BotMan\Messages\Outgoing\Question;
129
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
13-
use BotMan\BotMan\Messages\Conversations\Conversation;
14-
use Illuminate\Support\Facades\App;
10+
use BotMan\BotMan\Messages\Outgoing\Question;
1511
use Illuminate\Support\Facades\Validator;
1612

1713
class ExampleConversation extends Conversation
@@ -30,8 +26,7 @@ public function askFirstname()
3026
Button::create('Não')->value('não'),
3127
]);
3228
$this->ask($question,function(Answer $resposta){
33-
$opcao = $resposta;
34-
Log::info($opcao);
29+
$opcao = $resposta;
3530
if($opcao == 'sim'){
3631
$this->say('Seja bem vindo! Vamos fazer um cadastro para melhor atendê-lo. 😊');
3732
$formulario = Formulario::first();
@@ -74,7 +69,7 @@ public function askEmail()
7469

7570
public function run()
7671
{
77-
// This will be called immediately
72+
7873
$this->askFirstname();
7974

8075
}

app/Http/Controllers/BotManController.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace App\Http\Controllers;
44

55
use App\Conversations\Boasvindas;
6-
use BotMan\BotMan\BotMan;
7-
use Illuminate\Http\Request;
86
use App\Conversations\ExampleConversation;
7+
use BotMan\BotMan\BotMan;
8+
use Illuminate\Contracts\View\Factory;
9+
use Illuminate\View\View;
910

1011
class BotManController extends Controller
1112
{
@@ -20,7 +21,7 @@ public function handle()
2021
}
2122

2223
/**
23-
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
24+
* @return Factory|View
2425
*/
2526
public function home()
2627
{
@@ -36,6 +37,7 @@ public function home()
3637
*/
3738
public function startConversation(BotMan $bot)
3839
{
40+
3941
$bot->startConversation(new ExampleConversation());
4042
}
4143

app/Http/Controllers/PsicologoController.php

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Http\Controllers;
44

55
use App\Models\Atendimento;
6-
use App\Models\NotificacaoDeAtendimento;
76
use App\Models\User;
87
use Carbon\Carbon;
98
use Illuminate\Http\Request;
@@ -35,7 +34,6 @@ public function historicoList(Request $request){
3534
$filter = [
3635
Atendimento::AGUARDA_HORARIO,
3736
Atendimento::CONCLUIDO,
38-
Atendimento::EM_ATENDIMENTO,
3937
Atendimento::CANCELADO,
4038
Atendimento::REMARCADO,
4139
];

app/Jobs/GeraAtendimento.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Foundation\Bus\Dispatchable;
1313
use Illuminate\Queue\InteractsWithQueue;
1414
use Illuminate\Queue\SerializesModels;
15+
use Illuminate\Support\Facades\DB;
1516

1617
class GeraAtendimento implements ShouldQueue
1718
{
@@ -39,7 +40,7 @@ public function __construct($respostas ,$email,$motivo)
3940
public function handle()
4041
{
4142

42-
43+
Db::beginTransaction();
4344
$user = User::create([
4445
'name' => $this->respostas[0]['resposta'],
4546
'email' => $this->email,
@@ -74,5 +75,6 @@ public function handle()
7475
'notificado' => false,
7576
]);
7677
});
78+
Db::commit();
7779
}
7880
}

app/Models/NotificacaoPsicologo.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22
namespace App\Models;
33

44
use Illuminate\Database\Eloquent\Model;
5-
use Illuminate\Database\Eloquent\Relations\Pivot;
65

76
class NotificacaoPsicologo extends Model
87
{
9-
protected $fillable = [
10-
'notificacao_id',
11-
'psicologo_id',
12-
'notificado',
13-
];
8+
protected $guarded = [];
149

1510
public function psicologo(){
1611
return $this->belongsTo(User::class,'psicologo_id','id');

app/Providers/BotMan/DriverServiceProvider.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Providers\BotMan;
44

55
use BotMan\BotMan\Drivers\DriverManager;
6+
use BotMan\Drivers\Whatsappgo\WhatsappgoDriver;
67
use BotMan\Studio\Providers\DriverServiceProvider as ServiceProvider;
78

89
class DriverServiceProvider extends ServiceProvider
@@ -13,17 +14,16 @@ class DriverServiceProvider extends ServiceProvider
1314
*
1415
* @var array
1516
*/
16-
protected $drivers = [];
17+
protected $drivers = [
18+
];
1719

1820
/**
1921
* @return void
2022
*/
2123
public function boot()
2224
{
2325
parent::boot();
26+
DriverManager::loadDriver(WhatsappgoDriver::class);
2427

25-
foreach ($this->drivers as $driver) {
26-
DriverManager::loadDriver($driver);
27-
}
2828
}
2929
}

composer.json

100644100755
+12-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "botman/studio",
2+
"name": "progete-dev/psi-bot",
33
"description": "BotMan Chatbot framework.",
44
"keywords": [
55
"botman",
@@ -10,17 +10,18 @@
1010
"license": "MIT",
1111
"type": "project",
1212
"require": {
13-
"php": "^7.1.3",
13+
"php": "^7.4",
1414
"botman/botman": "2.0.x-dev",
1515
"botman/driver-web": "~1.0",
1616
"botman/studio-addons": "dev-master",
17-
"exatasmente/whatsapp-go" : "dev-master",
17+
"exatasmente/whatsapp-go": "@dev",
1818
"facade/ignition": "^2.0",
1919
"fideloper/proxy": "^4.0",
2020
"laravel/framework": "^7.0",
2121
"laravel/tinker": "^2.0",
2222
"laravel/ui": "^2.0",
23-
"livewire/livewire": "^1.1"
23+
"livewire/livewire": "^1.1",
24+
"ext-json": "*"
2425
},
2526
"require-dev": {
2627
"beyondcode/laravel-dump-server": "^1.0",
@@ -59,7 +60,8 @@
5960
],
6061
"post-install-cmd": [
6162
"Illuminate\\Foundation\\ComposerScripts::postInstall",
62-
"BotMan\\Studio\\Providers\\DriverServiceProvider::publishDriverConfigurations"
63+
"BotMan\\Studio\\Providers\\DriverServiceProvider::publishDriverConfigurations",
64+
"php artisan migrate --force"
6365
],
6466
"post-update-cmd": [
6567
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
@@ -68,10 +70,6 @@
6870
"post-autoload-dump": [
6971
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
7072
"@php artisan package:discover"
71-
],
72-
"post-install-cmd": [
73-
"Illuminate\\Foundation\\ComposerScripts::postInstall",
74-
"php artisan migrate:fresh --force --seed"
7573
]
7674
},
7775
"config": {
@@ -84,8 +82,11 @@
8482

8583
"repositories": [
8684
{
87-
"type": "vcs",
88-
"url": "https://github.com/exatasmente/whatsapp-go"
85+
"type": "path",
86+
"url": "./whatsapp-go",
87+
"options": {
88+
"symlink": true
89+
}
8990
},
9091
{
9192
"type": "vcs",

0 commit comments

Comments
 (0)