32 public static function get($botId, $dialogId, $prolong =
false)
34 if ($botId == $dialogId)
37 $result = self::getFromCache($botId);
39 $date = new \Bitrix\Main\Type\DateTime();
40 if (!($result[$dialogId] ??
null) || $result[$dialogId][
'DATE_EXPIRE'] < $date->getTimestamp())
42 $cache = \Bitrix\Main\Data\Cache::createInstance();
43 $cache->clean(
'token_'.$botId, self::CACHE_TOKEN_PATH);
45 $orm = \Bitrix\Im\Model\BotTokenTable::add(Array(
46 'DATE_EXPIRE' => $date->add(
'10 MINUTES'),
48 'DIALOG_ID' => $dialogId
50 if ($orm->getId() <= 0)
54 $addResult = $orm->getData();
56 $result[$dialogId] = Array(
57 'ID' => $orm->getId(),
59 'DIALOG_ID' => $addResult[
'DIALOG_ID'],
60 'DATE_EXPIRE' => $addResult[
'DATE_EXPIRE']->getTimestamp()
65 $date = new \Bitrix\Main\Type\DateTime();
66 $orm = \Bitrix\Im\Model\BotTokenTable::update($result[$dialogId][
'ID'], Array(
67 'DATE_EXPIRE' => $date->add(
'10 MINUTES')
69 if ($orm->isSuccess())
71 $addResult = $orm->getData();
72 $result[$dialogId][
'DATE_EXPIRE'] = $addResult[
'DATE_EXPIRE']->getTimestamp();
74 $cache = \Bitrix\Main\Data\Cache::createInstance();
75 $cache->initCache(self::CACHE_TOKEN_TTL,
'token_'.$botId, self::CACHE_TOKEN_PATH);
76 $cache->startDataCache();
77 $cache->endDataCache($result);
81 return $result[$dialogId];
87 if($cache->initCache(self::CACHE_TOKEN_TTL,
'token_'.$botId, self::CACHE_TOKEN_PATH))