1212
1313final readonly class WebsiteConversations
1414{
15- public function __construct (private CrispClient $ client ) {}
15+ public function __construct (private CrispClient $ client, private ? string $ websiteId = null ) {}
1616
1717 /**
1818 * @throws CrispException
@@ -21,7 +21,7 @@ public function __construct(private CrispClient $client) {}
2121 public function findWithSearch (int $ pageNumber = 1 , string $ searchQuery = '' , string $ searchType = '' , string $ searchOperator = '' , string $ includeEmpty = '' , string $ filterUnread = '' , string $ filterResolved = '' , string $ filterNotResolved = '' , string $ filterMention = '' , string $ filterAssigned = '' , string $ filterUnassigned = '' , string $ filterDateStart = '' , string $ filterDateEnd = '' , string $ orderDateCreated = '' , string $ orderDateUpdated = '' ): array
2222 {
2323 return $ this ->client ->websiteConversations ->findWithSearch (
24- config ('crisp.website_id ' ),
24+ $ this -> websiteId ?? config ('crisp.website_id ' ),
2525 $ pageNumber ,
2626 $ searchQuery ,
2727 $ searchType ,
@@ -47,7 +47,7 @@ public function findWithSearch(int $pageNumber = 1, string $searchQuery = '', st
4747 public function getList (int $ pageNumber = 1 ): array
4848 {
4949 return $ this ->client ->websiteConversations ->getList (
50- config ('crisp.website_id ' ),
50+ $ this -> websiteId ?? config ('crisp.website_id ' ),
5151 $ pageNumber
5252 );
5353 }
@@ -70,7 +70,7 @@ public function create(): array
7070 public function getOne (string $ sessionId ): array
7171 {
7272 return $ this ->client ->websiteConversations ->getOne (
73- config ('crisp.website_id ' ),
73+ $ this -> websiteId ?? config ('crisp.website_id ' ),
7474 $ sessionId
7575 );
7676 }
@@ -84,7 +84,7 @@ public function getOne(string $sessionId): array
8484 public function deleteOne (string $ sessionId ): array
8585 {
8686 return $ this ->client ->websiteConversations ->deleteOne (
87- config ('crisp.website_id ' ),
87+ $ this -> websiteId ?? config ('crisp.website_id ' ),
8888 $ sessionId
8989 );
9090 }
@@ -98,7 +98,7 @@ public function deleteOne(string $sessionId): array
9898 public function initiateOne (string $ sessionId ): array
9999 {
100100 return $ this ->client ->websiteConversations ->initiateOne (
101- config ('crisp.website_id ' ),
101+ $ this -> websiteId ?? config ('crisp.website_id ' ),
102102 $ sessionId
103103 );
104104 }
@@ -112,7 +112,7 @@ public function initiateOne(string $sessionId): array
112112 public function getMessages (string $ sessionId , string $ timestampBefore = '' ): array
113113 {
114114 return $ this ->client ->websiteConversations ->getMessages (
115- config ('crisp.website_id ' ),
115+ $ this -> websiteId ?? config ('crisp.website_id ' ),
116116 $ sessionId ,
117117 $ timestampBefore
118118 );
@@ -127,7 +127,7 @@ public function getMessages(string $sessionId, string $timestampBefore = ''): ar
127127 public function sendMessage (string $ sessionId , array $ message ): array
128128 {
129129 return $ this ->client ->websiteConversations ->sendMessage (
130- config ('crisp.website_id ' ),
130+ $ this -> websiteId ?? config ('crisp.website_id ' ),
131131 $ sessionId ,
132132 $ message
133133 );
@@ -142,7 +142,7 @@ public function sendMessage(string $sessionId, array $message): array
142142 public function acknowledgeMessages (string $ sessionId , array $ read ): array
143143 {
144144 return $ this ->client ->websiteConversations ->acknowledgeMessages (
145- config ('crisp.website_id ' ),
145+ $ this -> websiteId ?? config ('crisp.website_id ' ),
146146 $ sessionId ,
147147 $ read
148148 );
@@ -157,7 +157,7 @@ public function acknowledgeMessages(string $sessionId, array $read): array
157157 public function getRouting (string $ sessionId ): array
158158 {
159159 return $ this ->client ->websiteConversations ->getRouting (
160- config ('crisp.website_id ' ),
160+ $ this -> websiteId ?? config ('crisp.website_id ' ),
161161 $ sessionId
162162 );
163163 }
@@ -169,7 +169,7 @@ public function getRouting(string $sessionId): array
169169 public function assignRouting (string $ sessionId , array $ routing ): array
170170 {
171171 return $ this ->client ->websiteConversations ->assignRouting (
172- config ('crisp.website_id ' ),
172+ $ this -> websiteId ?? config ('crisp.website_id ' ),
173173 $ sessionId ,
174174 $ routing
175175 );
@@ -182,7 +182,7 @@ public function assignRouting(string $sessionId, array $routing): array
182182 public function getMeta (string $ sessionId ): array
183183 {
184184 return $ this ->client ->websiteConversations ->getMeta (
185- config ('crisp.website_id ' ),
185+ $ this -> websiteId ?? config ('crisp.website_id ' ),
186186 $ sessionId
187187 );
188188 }
@@ -194,7 +194,7 @@ public function getMeta(string $sessionId): array
194194 public function updateMeta (string $ sessionId , array $ metas ): array
195195 {
196196 return $ this ->client ->websiteConversations ->updateMeta (
197- config ('crisp.website_id ' ),
197+ $ this -> websiteId ?? config ('crisp.website_id ' ),
198198 $ sessionId ,
199199 $ metas
200200 );
@@ -207,7 +207,7 @@ public function updateMeta(string $sessionId, array $metas): array
207207 public function getOriginalMessage (string $ sessionId , string $ originalId ): array
208208 {
209209 return $ this ->client ->websiteConversations ->getOriginalMessage (
210- config ('crisp.website_id ' ),
210+ $ this -> websiteId ?? config ('crisp.website_id ' ),
211211 $ sessionId ,
212212 $ originalId
213213 );
@@ -224,7 +224,7 @@ public function getOriginalMessage(string $sessionId, string $originalId): array
224224 public function setState (string $ sessionId , string $ state ): array
225225 {
226226 return $ this ->client ->websiteConversations ->setState (
227- config ('crisp.website_id ' ),
227+ $ this -> websiteId ?? config ('crisp.website_id ' ),
228228 $ sessionId ,
229229 $ state
230230 );
@@ -237,7 +237,7 @@ public function setState(string $sessionId, string $state): array
237237 public function setBlock (string $ sessionId , bool $ blocked = true ): array
238238 {
239239 return $ this ->client ->websiteConversations ->setBlock (
240- config ('crisp.website_id ' ),
240+ $ this -> websiteId ?? config ('crisp.website_id ' ),
241241 $ sessionId ,
242242 $ blocked
243243 );
@@ -260,7 +260,7 @@ public function scheduleReminder(string $sessionId, string|CarbonInterface $date
260260 }
261261
262262 return $ this ->client ->websiteConversations ->scheduleReminder (
263- config ('crisp.website_id ' ),
263+ $ this -> websiteId ?? config ('crisp.website_id ' ),
264264 $ sessionId ,
265265 $ params
266266 );
@@ -277,7 +277,7 @@ public function scheduleReminder(string $sessionId, string|CarbonInterface $date
277277 public function getOneCrispConversation (string $ sessionId ): CrispConversation
278278 {
279279 return CrispConversation::from (
280- $ this ->client ->websiteConversations ->getOne (config ('crisp.website_id ' ), $ sessionId )
280+ $ this ->client ->websiteConversations ->getOne ($ this -> websiteId ?? config ('crisp.website_id ' ), $ sessionId )
281281 );
282282 }
283283
@@ -291,7 +291,7 @@ public function getOneCrispConversation(string $sessionId): CrispConversation
291291 public function getOneLastMessage (string $ sessionId ): string
292292 {
293293 $ getOneResponse = $ this ->client ->websiteConversations ->getOne (
294- config ('crisp.website_id ' ),
294+ $ this -> websiteId ?? config ('crisp.website_id ' ),
295295 $ sessionId
296296 );
297297
@@ -302,9 +302,9 @@ public function getOneLastMessage(string $sessionId): string
302302 * Bonus Method
303303 * Get the conversation link for a given session.
304304 */
305- public static function getConversationLink (string $ sessionId ): string
305+ public static function getConversationLink (string $ sessionId, ? string $ websiteId = null ): string
306306 {
307- $ websiteId = config ('crisp.website_id ' );
307+ $ websiteId = $ websiteId ?? config ('crisp.website_id ' );
308308
309309 return "https://app.crisp.chat/website/ {$ websiteId }/inbox/ {$ sessionId }/ " ;
310310 }
0 commit comments