Output message "please wait" before call api

v4

#1

Hello

I would like to send a message “please wait we are working on your request” before to call my api.
But this message appear when I’ send a message with the results of api.
In my web plugin, I used delegate component. Bellow you can see my code

 onStartPmChecklist() {
return this.$delegate(StartDateListOfPmCheckListComponent, {
  resolve: {
    successStartDate: this.onEndPmChecklist,
  },
});
  }

  onEndPmChecklist(startDate: string) {
this.$component.data.startDate = startDate;
return this.$delegate(EndDateListOfPmCheckListComponent, {
  resolve: {
    successEndDate: this.onListPmChecklist,
  },
});
  }

  onListPmChecklist(endDate: string) {
this.$data.serialNumber = this.$component.data.serialNumber;
this.$data.endDate = endDate;
this.$data.startDate = this.$component.data.startDate;
return this.$delegate(ListOfPmCheckListComponent, {
  resolve: {
    needAnotherHelp: this.onNeedAnotherHelp,
    notNeedAnotherHelp: this.onNotNeedAnotherHelp,
  },
});
  }

const TPL_TICKET = 'pm_checkList';

@Component()
export class ListOfPmCheckListComponent extends BaseComponent {
  async START() {
    const system_id = this.$data.serialNumber;
    const f_api_endDate = this.$data.endDate;
    const f_api_startDate = this.$data.startDate;
    console.log(
      `system_id : ${system_id}, f_api_startDate : ${f_api_startDate}, f_api_endDate :${f_api_endDate}`,
    );
    this.$send('please wait');
    const data: PmCheckListCRM[] = await checkListApi(system_id, f_api_startDate, f_api_endDate);
   

    if (data.length == 0) {
      this.$send({ message: this.$t('emptyPMCheckList') });
    } else {
      this.$send([
        {
          message: this.$t('belowPreventive'),
        },
      ]);

      const arrPdfFile: PDFFile[] = [];
      const arrInfoPM: InfoPM[] = [];

      for (const index in data) {
        const obj = new PDFFile(
          `PMCheckList_${data[index].caseNumber}.pdf`,
          data[index].checkListInfo.pdfEncrypt,
        );

        const info = new InfoPM(data[index].caseNumber, data[index].endDate);

        arrPdfFile.push(obj!);
        arrInfoPM.push(info);

        this.$send({
          message: this.$t('detailPM', {
            case_number: data[index].caseNumber,
            close_date: data[index].endDate,
            ownername: data[index].ownername,
          }),
        });
      }
    }
    return this.$send(YesNoOutput, { message: this.$t('needAnotherHelpService') });
  }

  @Intents(['YesIntent'])
  needAnotherHelp() {
    return this.$resolve('needAnotherHelp');
  }

  @Intents(['NoIntent'])
  notNeedAnotherHelp() {
    return this.$resolve('notNeedAnotherHelp');
  }

  UNHANDLED() {
    this.$send({ message: this.$t('responseNotValid') });
    return this.START();
  }
}

Can you help me, please ?

Romain


#2

Thank you @Romain.Rivolta. This sounds interesting, similar to how progressive responses work for Alexa, and how other asynchronous platforms like Facebook Messenger and Google Business Messages work: https://www.jovo.tech/docs/output#send-multiple-responses

Right now, this doesn’t work for our existing web clients, but this sounds like a great addition.

Maybe we could build this by using sockets @AlexSwe?


#3

Thanks very much @jan. We wait the response by @AlexSwe
Best regards


#4

I like the idea.

I heard @norbert and team are working on a web socket integration :slight_smile:


#5

Hello

Thanks you for your answers.
@AlexSwe and @norbert do you have an approximate date for this package ?

Best Regards,
Romain


#6

Hello
@AlexSwe and @norbert do you have any news about a message “please wait we are working on your request” before to call my api. But this message appear when I’ send a message with the results of api.

Thanks


#7

Hi,

support for async sends via web socket are features of the specific platform you are using. What kind of platform are u using in your project ? Jovo Core or a custom platform implementation ?


#8

@norbert
I used these packages
import { CorePlatform } from ‘@jovotech/platform-core’;
import { WebPlatform } from ‘@jovotech/platform-web’;

async getContractSystemIDApi(system_id: string): Promise<void | ContractCRM> {
this.$send("please wait")
try {
  await checkTokenOAuth(this);
  const data: ContractCRM | number = await checkContractSystemIDApi(system_id, this.$user.data.access_token_oauth2);
  if (typeof data === 'number') {
    if (data === ErrorCRMAPI.OAUTH_ACCESS_TOKEN_MISSING) {
      const updatedObject = withoutProperty(this.$user.data, [
        'access_token_oauth2',
      ]);
      this.$user.data = updatedObject;
      return this.getContractSystemIDApi(this.$component.data.sr);
    }
    else if (data === ErrorCRMAPI.SYSTEM_ID_NOT_EXIST) return this.$resolve('invalidSystemID');
    else if (data === ErrorCRMAPI.CONTRACT_NOT_FOUND) return this.$resolve('notContract');
  }
  const contractCRM = data as ContractCRM;

  if (contractCRM === null) return this.$resolve('emptyContract');

  const contract: ContractCRM = Object.assign({}, false, true, undefined, null, 0, {
    systemId: contractCRM.systemId,
    contractNumber: contractCRM.contractNumber,
    servicePlanName: contractCRM.servicePlanName,
    endDate: contractCRM.endDate,
    normalizeProduct: contractCRM.normalizeProduct,
  }) as {
    systemId: string;
    contractNumber: string;
    servicePlanName: string;
    endDate: string;
    normalizeProduct: string;
  };
  return contract;
} catch (err) {
  console.log(err);
  throw new JovoError({ message: err as string });
}

}


#9

Hi @norbert

Do you have any news about the display of the message “please wait” during call an api

Thx
Romain