new(core.gbapp): New API endpoint.
This commit is contained in:
		
							parent
							
								
									cafebf6fe2
								
							
						
					
					
						commit
						5655605d29
					
				
					 1 changed files with 9 additions and 10 deletions
				
			
		| 
						 | 
					@ -70,6 +70,7 @@ import { GBVMService } from './GBVMService.js';
 | 
				
			||||||
 * Default check interval for user replay
 | 
					 * Default check interval for user replay
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
const DEFAULT_HEAR_POLL_INTERVAL = 500;
 | 
					const DEFAULT_HEAR_POLL_INTERVAL = 500;
 | 
				
			||||||
 | 
					const API_RETRIES = 120;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Base services of conversation to be called by BASIC.
 | 
					 * Base services of conversation to be called by BASIC.
 | 
				
			||||||
| 
						 | 
					@ -1270,14 +1271,15 @@ export class DialogKeywords {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    let messages = [];
 | 
					    let messages = [];
 | 
				
			||||||
 | 
					 | 
				
			||||||
    GBLog.info(`MessageBot: Starting message polling ${conversation.conversationId}).`);
 | 
					    GBLog.info(`MessageBot: Starting message polling ${conversation.conversationId}).`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const worker = async () => {
 | 
					    let count = API_RETRIES;
 | 
				
			||||||
 | 
					    while (count--) {
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      await GBUtil.sleep(DEFAULT_HEAR_POLL_INTERVAL);
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        const response = await client.apis.Conversations.Conversations_GetActivities({
 | 
					        const response = await client.apis.Conversations.Conversations_GetActivities({
 | 
				
			||||||
          conversationId: conversation.conversationId,
 | 
					          conversationId: conversation.conversationId,
 | 
				
			||||||
          watermark: conversation.watermark
 | 
					          watermark: conversation.watermark
 | 
				
			||||||
| 
						 | 
					@ -1285,7 +1287,6 @@ export class DialogKeywords {
 | 
				
			||||||
        conversation.watermarkMap = response.obj.watermark;
 | 
					        conversation.watermarkMap = response.obj.watermark;
 | 
				
			||||||
        let activities = response.obj.activites;
 | 
					        let activities = response.obj.activites;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (activities && activities.length) {
 | 
					        if (activities && activities.length) {
 | 
				
			||||||
          activities = activities.filter(m => m.from.id === min.botId && m.type === 'message');
 | 
					          activities = activities.filter(m => m.from.id === min.botId && m.type === 'message');
 | 
				
			||||||
          if (activities.length) {
 | 
					          if (activities.length) {
 | 
				
			||||||
| 
						 | 
					@ -1294,18 +1295,16 @@ export class DialogKeywords {
 | 
				
			||||||
              GBLogEx.info(min, `MESSAGE BOT answer from bot: ${activity.text}`);
 | 
					              GBLogEx.info(min, `MESSAGE BOT answer from bot: ${activity.text}`);
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					          return messages.join('\n');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return messages.join('\n');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      } catch (err) {
 | 
					      } catch (err) {
 | 
				
			||||||
        GBLog.error(
 | 
					        GBLog.error(
 | 
				
			||||||
          `Error calling printMessages API ${err.data === undefined ? err : err.data} ${err.errObj ? err.errObj.message : ''
 | 
					          `Error calling printMessages in messageBot API ${err.data === undefined ? err : err.data} ${err.errObj ? err.errObj.message : ''
 | 
				
			||||||
          }`
 | 
					          }`
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					        return err;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    setInterval(worker, DEFAULT_HEAR_POLL_INTERVAL);
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue