-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexampleBot.php
84 lines (73 loc) · 2.22 KB
/
exampleBot.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
73
74
75
76
77
78
79
80
81
82
83
84
<?php
$data = file_get_contents('php://input');
$response = [];
if($data != ''){
$path_file = 'mediaBot/';
//FROM WHATSAPP API
$array = json_decode($data, TRUE);
if(is_array($array) && !empty($array)){
$body = array_key_exists('body', $array) ? $array['body'] : null; // body of message
$type = array_key_exists('type', $array) ? $array['type'] : null; // type of message
$from = array_key_exists('from', $array) ? preg_replace('~\D~', '', $array['from']) : null; // from
$to = array_key_exists('to', $array) ? preg_replace('~\D~', '', $array['to']) : null; // to
//DEFAULT MESSAGE
$caption = "Hello {$type} {$from}";
//EXAMPLE SEND | LOCATION
/*
$args = [
'location' => [
'latitude' => '23.3848867',
'longitude' => '-111.582129',
'name' => $caption
]
];
$type_response = 'media';
$message = json_encode($args, TRUE);
*/
//EXAMPLE SEND | PREVIEW LINK
/*
$args = [
'content' => "https://github.com {$caption}",
'preview' => TRUE
];
$type_response = 'media';
$message = json_encode($args, TRUE);
*/
//EXAMPLE SEND | FILE (PDF, JPG, PNG, DOCX, STICKER/WEBP)
/*
$array_file = ['jpgFile.jpg', 'pdfFile.pdf', 'pngFile.png', 'wordFile.docx', 'stickerFile.webp'];
$file_name = $array_file[4];
$file = $path_file.$file_name;
$file_mimetype = mime_content_type($file);
$attachment = base64_encode(file_get_contents($file));
$args = [
'filename' => $file_name,
'attachment' => $attachment,
'mimetype' => $file_mimetype,
'caption' => $caption,
];
$type_response = 'media';
$message = json_encode($args, TRUE);
//echo $attachment;exit;
*/
//EXAMPLE SEND | SINGLE MESSAGE
/*
$message = $caption;
$type_response = 'message';
*/
//EXAMPLE SEND | MULTIPLE MESSAGE
/*
$message = [$caption, $caption];
$type_response = 'message';
*/
//SEND TO WHATSAPP
$response = [
'status' => TRUE,
'type' => $type_response,
'message' => $message
];
}
}
//RETURN JSON
header('Content-Type: application/json');
echo json_encode($response, TRUE);