@@ -140,6 +140,10 @@ export default (): void => {
140140
141141 b . on ( 'getRoutingConfig' , async ( ) => {
142142 const agent = rand ( agents ) ;
143+
144+ if ( ! agent ) {
145+ return ;
146+ }
143147 await agent . getRoutingConfig ( ) ;
144148 const { departments } = ( await agent . getAgentDepartments ( ) ) || {
145149 departments : [ ] ,
@@ -151,11 +155,17 @@ export default (): void => {
151155
152156 b . on ( 'getQueuedInquiries' , async ( ) => {
153157 const agent = rand ( agents ) ;
158+ if ( ! agent ) {
159+ return ;
160+ }
154161 await agent . getQueuedInquiries ( ) ;
155162 } ) ;
156163
157164 b . on ( 'takeInquiry' , async ( ) => {
158165 const agent = rand ( agents ) ;
166+ if ( ! agent ) {
167+ return ;
168+ }
159169 const response = await agent . getQueuedInquiries ( ) ;
160170 if ( ! response ?. inquiries ) {
161171 return ;
@@ -170,6 +180,10 @@ export default (): void => {
170180 }
171181
172182 const processedInquiry = rand ( inquiries ) ;
183+
184+ if ( ! processedInquiry ) {
185+ return ;
186+ }
173187 try {
174188 // Re-fetch inquiry
175189 await agent . getInquiry ( processedInquiry . _id ) ;
@@ -186,6 +200,9 @@ export default (): void => {
186200
187201 b . on ( 'message' , async ( ) => {
188202 const agent = rand ( agents ) ;
203+ if ( ! agent ) {
204+ return ;
205+ }
189206 const sub = agent . getRandomLivechatSubscription ( ) ;
190207
191208 if ( ! sub ) {
0 commit comments