Skip to content

Commit 6882bed

Browse files
vdomahribagek
andauthored
Added bot_id config parameter. new IncomingMessage with bot_id: using in getConversationIdentifier (botman#1207)
Co-authored-by: Art <alchemistt@ukr.net>
1 parent 203e7f5 commit 6882bed

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/BotMan.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ class BotMan
129129
*/
130130
public function __construct(CacheInterface $cache, DriverInterface $driver, $config, StorageInterface $storage)
131131
{
132+
if (!isset($config['bot_id'])) {
133+
$config['bot_id'] = '';
134+
}
135+
132136
$this->cache = $cache;
133-
$this->message = new IncomingMessage('', '', '');
137+
$this->message = new IncomingMessage('', '', '', null, $config['bot_id']);
134138
$this->driver = $driver;
135139
$this->config = $config;
136140
$this->storage = $storage;
@@ -436,7 +440,7 @@ public function listen()
436440
}
437441

438442
$this->firedDriverEvents = false;
439-
$this->message = new IncomingMessage('', '', '');
443+
$this->message = new IncomingMessage('', '', '', null, $this->config['bot_id']);
440444
}
441445
} catch (\Throwable $e) {
442446
$this->exceptionHandler->handleException($e, $this);
@@ -555,8 +559,12 @@ public function say($message, $recipients, $driver = null, $additionalParameters
555559

556560
$recipients = \is_array($recipients) ? $recipients : [$recipients];
557561

562+
if (!isset($this->config['bot_id'])) {
563+
$this->config['bot_id'] = '';
564+
}
565+
558566
foreach ($recipients as $recipient) {
559-
$this->message = new IncomingMessage('', $recipient, '');
567+
$this->message = new IncomingMessage('', $recipient, '', null, $this->config['bot_id']);
560568
$response = $this->reply($message, $additionalParameters);
561569
}
562570

@@ -580,7 +588,7 @@ public function ask($question, $next, $additionalParameters = [], $recipient = n
580588
if (\is_string($driver)) {
581589
$driver = DriverManager::loadFromName($driver, $this->config);
582590
}
583-
$this->message = new IncomingMessage('', $recipient, '');
591+
$this->message = new IncomingMessage('', $recipient, '', null, $this->config['bot_id']);
584592
$this->setDriver($driver);
585593
}
586594

src/Messages/Incoming/IncomingMessage.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class IncomingMessage
1717
/** @var string */
1818
protected $recipient;
1919

20+
/** @var string */
21+
protected $bot_id;
22+
2023
/** @var array */
2124
protected $images = [];
2225

@@ -44,12 +47,13 @@ class IncomingMessage
4447
/** @var bool */
4548
protected $isFromBot = false;
4649

47-
public function __construct($message, $sender, $recipient, $payload = null)
50+
public function __construct($message, $sender, $recipient, $payload = null, $bot_id = '')
4851
{
4952
$this->message = $message;
5053
$this->sender = $sender;
5154
$this->recipient = $recipient;
5255
$this->payload = $payload;
56+
$this->bot_id = $bot_id;
5357
}
5458

5559
/**
@@ -89,7 +93,7 @@ public function getText()
8993
*/
9094
public function getConversationIdentifier()
9195
{
92-
return 'conversation-'.sha1($this->getSender()).'-'.sha1($this->getRecipient());
96+
return 'conversation-'.$this->bot_id.sha1($this->getSender()).'-'.sha1($this->getRecipient());
9397
}
9498

9599
/**
@@ -99,7 +103,7 @@ public function getConversationIdentifier()
99103
*/
100104
public function getOriginatedConversationIdentifier()
101105
{
102-
return 'conversation-'.sha1($this->getSender()).'-'.sha1('');
106+
return 'conversation-'.$this->bot_id.sha1($this->getSender()).'-'.sha1('');
103107
}
104108

105109
/**

src/Traits/HandlesConversations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait HandlesConversations
2121
public function startConversation(Conversation $instance, $recipient = null, $driver = null)
2222
{
2323
if (! is_null($recipient) && ! is_null($driver)) {
24-
$this->message = new IncomingMessage('', $recipient, '');
24+
$this->message = new IncomingMessage('', $recipient, '', null, $this->config['bot_id']);
2525
$this->driver = DriverManager::loadFromName($driver, $this->config);
2626
}
2727
$instance->setBot($this);

0 commit comments

Comments
 (0)