27 const AUDIO_DIR =
'http://dl.bitrix24.com/sender/audiocall/';
28 const METADATA_FILE =
'http://dl.bitrix24.com/sender/audiocall/metadata.json';
36 $data = self::getMetadata();
37 return $data ? $data[
'langs'] : [];
50 if ($templateType && $templateType !==
'BASE')
54 if ($messageCode && $messageCode !==
Message\iBase::CODE_AUDIO_CALL)
59 return static::getTemplates($templateId);
69 if (!self::presetExists($code))
73 $filePath = static::AUDIO_DIR . static::getCodeWithLang($code) .
'.mp3';
94 $code = self::getCodeWithLang($code);
95 $data = self::getMetadata();
96 return $data[
'durations'][$code] ??
false;
105 $messageCode = Message\iBase::CODE_AUDIO_CALL;
108 $code = mb_strtolower($item[
'CODE']);
109 if (self::presetExists($code))
122 private static function getCodeWithLang($code)
124 $lang = self::getLang();
125 return $lang .
'_' . $code;
132 private static function getLang()
134 $lang = mb_strtolower(LANGUAGE_ID);
135 $supportedLangs = static::getSupportedLangs();
136 $lang = in_array($lang, $supportedLangs) ? $lang : array_shift($supportedLangs);
145 private static function getTemplates($templateId =
null)
148 $messageCode = Message\iBase::CODE_AUDIO_CALL;
152 $code = mb_strtolower($item[
'CODE']);
153 $presetCode = mb_strtolower($messageCode.
"_".$code);
154 if (!self::presetExists($code))
158 if($templateId && $presetCode !== $templateId)
166 'MESSAGE_CODE' => array($messageCode),
168 'HOT' => $item[
'HOT'],
169 'ICON' => $item[
'ICON'],
171 'NAME' => $item[
'NAME'],
172 'DESC' => $item[
'DESC'],
175 'CODE' =>
'AUDIO_FILE',
176 'VALUE' => static::getAudioFileUrlByCode($code),
190 private static function getMetadata()
192 static $failed =
false;
199 $cacheId =
'sender_audiocall_metadata';
200 $cachePath =
'/sender/audiocall_metadata/';
201 $cache = \Bitrix\Main\Application::getInstance()->getCache();
202 if($cache->initCache($cacheTtl, $cacheId, $cachePath))
204 return $cache->getVars();
210 $cache->startDataCache();
212 $request =
new HttpClient([
213 "socketTimeout" => 5,
216 $request->get(static::METADATA_FILE);
217 if($request->getStatus() == 200)
221 $result = Json::decode($request->getResult());
223 catch (ArgumentException $e)
227 if (is_array($result))
229 $cache->endDataCache($result);
234 $cache->abortDataCache();
static loadMessages($file)
static getListByType($type)