File tree Expand file tree Collapse file tree 8 files changed +189
-3
lines changed Expand file tree Collapse file tree 8 files changed +189
-3
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Console \Commands ;
4
+
5
+ use Illuminate \Console \Command ;
6
+ use Illuminate \Support \Facades \Log ;
7
+ use Vonage \Client ;
8
+ use Vonage \Voice \Endpoint \Phone ;
9
+ use Vonage \Voice \NCCO \Action \Talk ;
10
+ use Vonage \Voice \NCCO \NCCO ;
11
+ use Vonage \Voice \OutboundCall ;
12
+
13
+ class MakeVoiceCallWithNcco extends Command
14
+ {
15
+ /**
16
+ * The name and signature of the console command.
17
+ *
18
+ * @var string
19
+ */
20
+ protected $ signature = 'vonage:voice ' ;
21
+
22
+ /**
23
+ * The console command description.
24
+ *
25
+ * @var string
26
+ */
27
+ protected $ description = 'Make a voice call with an NCCO object ' ;
28
+
29
+ /**
30
+ * Create a new command instance.
31
+ *
32
+ * @return void
33
+ */
34
+ public function __construct ()
35
+ {
36
+ parent ::__construct ();
37
+ }
38
+
39
+ /**
40
+ * Execute the console command.
41
+ *
42
+ * @return int
43
+ */
44
+ public function handle (Client $ client )
45
+ {
46
+ $ outboundCall = new OutboundCall (
47
+ new Phone ('14843331234 ' ),
48
+ new Phone ('14843335555 ' )
49
+ );
50
+
51
+ $ ncco = new NCCO ();
52
+ $ ncco ->addAction (new Talk ('This is a text to speech call from Vonage ' ));
53
+
54
+ $ outboundCall ->setNCCO ($ ncco );
55
+
56
+ $ response = $ client ->voice ()->createOutboundCall ($ outboundCall );
57
+ Log::info (var_dump ($ response ));
58
+ return 0 ;
59
+ }
60
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Console \Commands ;
4
+
5
+ use Illuminate \Console \Command ;
6
+ use Vonage \Client ;
7
+ use Vonage \SMS \Message \SMS ;
8
+
9
+ class SendSMS extends Command
10
+ {
11
+ /**
12
+ * The name and signature of the console command.
13
+ *
14
+ * @var string
15
+ */
16
+ protected $ signature = 'vonage:sms ' ;
17
+
18
+ /**
19
+ * The console command description.
20
+ *
21
+ * @var string
22
+ */
23
+ protected $ description = 'Send a test SMS ' ;
24
+
25
+ /**
26
+ * Create a new command instance.
27
+ *
28
+ * @return void
29
+ */
30
+ public function __construct ()
31
+ {
32
+ parent ::__construct ();
33
+ }
34
+
35
+ /**
36
+ * Execute the console command.
37
+ *
38
+ * @return int
39
+ */
40
+ public function handle (Client $ client )
41
+ {
42
+ $ text = new SMS ('0123445 ' , '123345 ' , 'Hello from Vonage! ' );
43
+ $ response = $ client ->sms ()->send ($ text );
44
+ var_dump ($ response );
45
+ return 0 ;
46
+ }
47
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Http \Controllers ;
4
+
5
+ use Illuminate \Http \Request ;
6
+ use Vonage \Client ;
7
+
8
+ class IncomingCallController extends Controller
9
+ {
10
+ public function __invoke (Request $ request , Client $ client )
11
+ {
12
+ $ ncco = [
13
+ [
14
+ 'action ' => 'talk ' ,
15
+ 'text ' => 'Thank you for calling Vonage! '
16
+ ]
17
+ ];
18
+
19
+ return response ()->json ($ ncco );
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Http \Controllers ;
4
+
5
+ use Illuminate \Http \Request ;
6
+ use Illuminate \Support \Facades \Log ;
7
+ use Vonage \SMS \Webhook \Factory ;
8
+
9
+ class IncomingSmsController extends Controller
10
+ {
11
+ public function __invoke (Request $ request )
12
+ {
13
+ Log::info ('Hit the SMS inbound endpoint ' );
14
+ $ sms = Factory::createFromGlobals ($ request );
15
+ Log::info (var_dump ($ sms ));
16
+ }
17
+ }
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ class Kernel extends HttpKernel
35
35
\Illuminate \Session \Middleware \StartSession::class,
36
36
// \Illuminate\Session\Middleware\AuthenticateSession::class,
37
37
\Illuminate \View \Middleware \ShareErrorsFromSession::class,
38
- \App \Http \Middleware \VerifyCsrfToken::class,
38
+ // \App\Http\Middleware\VerifyCsrfToken::class,
39
39
\Illuminate \Routing \Middleware \SubstituteBindings::class,
40
40
],
41
41
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Providers ;
4
+
5
+ use Illuminate \Support \ServiceProvider ;
6
+ use Vonage \Client ;
7
+
8
+ class VonageProvider extends ServiceProvider
9
+ {
10
+ /**
11
+ * Register services.
12
+ *
13
+ * @return void
14
+ */
15
+ public function register ()
16
+ {
17
+ //
18
+ }
19
+
20
+ /**
21
+ * Bootstrap services.
22
+ *
23
+ * @return void
24
+ */
25
+ public function boot ()
26
+ {
27
+ $ this ->app ->bind (Client::class, function () {
28
+ $ basic = new Client \Credentials \Basic (config ('vonage.apiKey ' ), config ('vonage.apiSecret ' ));
29
+ $ keypair = new Client \Credentials \Keypair (
30
+ file_get_contents (base_path () . '/ ' . config ('vonage.apiKeyPath ' )),
31
+ config ('vonage.applicationId ' )
32
+ );
33
+
34
+ return new Client (new Client \Credentials \Container ($ basic , $ keypair ));
35
+ });
36
+ }
37
+ }
Original file line number Diff line number Diff line change 2
2
3
3
return [
4
4
'apiKey ' => env ('API_KEY ' ),
5
- 'apiSecret ' => env ('API_SECRET ' )
5
+ 'apiSecret ' => env ('API_SECRET ' ),
6
+ 'apiKeyPath ' => env ('API_KEY_PATH ' ),
7
+ 'applicationId ' => env ('APPLICATION_ID ' )
6
8
];
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
use App \Http \Controllers \IncomingCallController ;
4
+ use App \Http \Controllers \IncomingSmsController ;
4
5
use Illuminate \Support \Facades \Route ;
5
6
6
7
/*
18
19
return view ('welcome ' );
19
20
});
20
21
21
- Route::get ('/incoming ' , IncomingCallController::class);
22
+ Route::get ('/incomingVoice ' , IncomingCallController::class);
23
+ Route::post ('/incomingSms ' , IncomingSmsController::class);
You can’t perform that action at this time.
0 commit comments