Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Utils.php
1<?php
2
4
10
11class Utils extends WhatsApp\Utils
12{
13 public function testConnection(): Result
14 {
15 $requestParams = ['imType' => 'WHATSAPP'];
16
19 $this->optionManager->getOption(InternalOption::API_KEY),
21 )
22 ;
23
24 return $externalSender->callExternalMethod('im-subject/by-apikey', $requestParams);
25 }
26
27 public function getMessageTemplates(string $subject = ''): Result
28 {
29 $result = new Result();
30 if (defined('WA_EDNA_RU_TEMPLATES_STUB') && WA_EDNA_RU_TEMPLATES_STUB === true)
31 {
32 return $result->setData($this->getMessageTemplatesStub());
33 }
34
35 $params = ['imType' => 'whatsapp'];
36 if ($subject !== '')
37 {
38 $params['subject'] = $subject;
39 }
40
43 $this->optionManager->getOption(InternalOption::API_KEY),
45 );
46
47 $templatesRequestResult = $externalSender->callExternalMethod('getOutMessageMatchers', $params);
48 if ($templatesRequestResult->isSuccess())
49 {
50 $templates = $templatesRequestResult->getData();
51
52 $checkErrors = $this->checkForErrors($templates);
53 if ($checkErrors->isSuccess())
54 {
55 $templates = $this->removeUnsupportedTemplates($templates);
56 $result->setData($templates);
57 }
58 else
59 {
60 $result->addErrors($checkErrors->getErrors());
61 }
62 }
63 else
64 {
65 $result->addErrors($templatesRequestResult->getErrors());
66 }
67
68 return $result;
69 }
70
77 protected function getMessageTemplatesStub(): array
78 {
79 return [
80 'result' => [
81 [
82 'id' => 206,
83 'name' => 'test template',
84 'imType' => 'whatsapp',
85 'language' => 'AU',
86 'content' => [
87 'header' => [],
88 'text' => 'whatsapp text',
89 'footer' => [
90 'text' => 'footer text'
91 ],
92 'keyboard' => [
93 'row' => [
94 'buttons' => [
95 [
96 'text' => 'button1',
97 'payload' => 'button1',
98 'buttonType' => 'QUICK_REPLY'
99 ]
100 ]
101 ]
102 ]
103 ],
104 'category' => 'ISSUE_UPDATE',
105 'status' => 'PENDING',
106 'createdAt' => '2020-11-12T11:31:39.000+0000',
107 'updatedAt' => '2020-11-12T11:31:39.000+0000'
108 ],
109 [
110 'id' => 207,
111 'name' => 'one more template',
112 'imType' => 'whatsapp',
113 'language' => 'AU',
114 'content' => [
115 'header' => [],
116 'text' => 'one more template',
117 'footer' => [
118 'text' => 'footer text'
119 ],
120 'keyboard' => [
121 'row' => [
122 'buttons' => [
123 [
124 'text' => 'button1',
125 'payload' => 'button1',
126 'buttonType' => 'QUICK_REPLY'
127 ]
128 ]
129 ]
130 ]
131 ],
132 'category' => 'ISSUE_UPDATE',
133 'status' => 'PENDING',
134 'createdAt' => '2020-11-12T11:31:39.000+0000',
135 'updatedAt' => '2020-11-12T11:31:39.000+0000'
136 ]
137 ],
138 'code' => 'ok'
139 ];
140 }
141}