/
AddStartButtonPayload.php
72 lines (61 loc) · 1.66 KB
/
AddStartButtonPayload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace BotMan\Drivers\Facebook\Commands;
use BotMan\BotMan\Http\Curl;
use Illuminate\Console\Command;
class AddStartButtonPayload extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'botman:facebookAddStartButton';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Add a Facebook Get Started button with a payload';
/**
* @var Curl
*/
private $http;
/**
* Create a new command instance.
*
* @param Curl $http
*/
public function __construct(Curl $http)
{
parent::__construct();
$this->http = $http;
}
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$payload = config('botman.facebook.start_button_payload');
if (! $payload) {
$this->error('You need to add a Facebook payload data to your BotMan Facebook config in facebook.php.');
exit;
}
$response = $this->http->post(
'https://graph.facebook.com/v3.0/me/messenger_profile?access_token='.config('botman.facebook.token'),
[],
[
'get_started' => [
'payload' => $payload,
],
]
);
$responseObject = json_decode($response->getContent());
if ($response->getStatusCode() == 200) {
$this->info('Get Started payload was set to: '.$payload);
} else {
$this->error('Something went wrong: '.$responseObject->error->message);
}
}
}