{ "version": 3, "sources": ["libs/conversation/core/src/lib/template.service.ts"], "sourcesContent": ["import { HttpResponse } from '@angular/common/http';\nimport { Injectable, inject } from '@angular/core';\nimport {\n ConversationApiService,\n GlobalParticipantType,\n ListMessageTemplateRequest,\n MessageTemplate,\n SubjectParticipant,\n} from '@vendasta/conversation';\nimport { GetMessageTemplateResponse, ListMessageTemplateResponse } from '@vendasta/conversation/lib/_internal/objects';\nimport { SnackbarService } from '@vendasta/galaxy/snackbar-service';\nimport { Observable, combineLatest, firstValueFrom, of, switchMap } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\nimport { ACCOUNT_GROUP_ID_TOKEN, PARTNER_ID_TOKEN } from './tokens';\n\n@Injectable({ providedIn: 'root' })\nexport class TemplateService {\n private readonly conversationApiService = inject(ConversationApiService);\n private readonly snackbarService = inject(SnackbarService);\n\n private readonly accountGroupId$ = inject(ACCOUNT_GROUP_ID_TOKEN);\n private readonly partnerId$ = inject(PARTNER_ID_TOKEN);\n\n listTemplates(cursor: string, pageSize: number): Observable {\n return combineLatest([this.accountGroupId$, this.partnerId$]).pipe(\n switchMap(([accountGroupId, partnerId]) => {\n const subjectParticipant = new SubjectParticipant({\n participantType: accountGroupId\n ? GlobalParticipantType.GLOBAL_PARTICIPANT_TYPE_ACCOUNT_GROUP\n : GlobalParticipantType.GLOBAL_PARTICIPANT_TYPE_PARTNER,\n internalParticipantId: accountGroupId || partnerId,\n });\n\n return this.conversationApiService.listMessageTemplate(\n new ListMessageTemplateRequest({\n pagingOptions: { cursor: cursor, pageSize: pageSize },\n subjectParticipant: subjectParticipant,\n }),\n );\n }),\n );\n }\n\n async createTemplate(template: MessageTemplate): Promise {\n const sb = await firstValueFrom(\n combineLatest([this.accountGroupId$, this.partnerId$]).pipe(\n map(([accountGroupId, partnerId]) => {\n return new SubjectParticipant({\n participantType: accountGroupId\n ? GlobalParticipantType.GLOBAL_PARTICIPANT_TYPE_ACCOUNT_GROUP\n : GlobalParticipantType.GLOBAL_PARTICIPANT_TYPE_PARTNER,\n internalParticipantId: accountGroupId || partnerId,\n });\n }),\n ),\n );\n await firstValueFrom(\n this.conversationApiService.createMessageTemplate({\n template: template,\n subjectParticipant: sb,\n }),\n );\n }\n\n async delete(templateId: string): Promise> {\n return await firstValueFrom(this.conversationApiService.deleteMessageTemplate({ templateId: templateId }));\n }\n\n async updateTemplate(template: MessageTemplate): Promise {\n await firstValueFrom(\n this.conversationApiService.updateMessageTemplate({\n template: template,\n fieldMask: {\n paths: ['name', 'content'],\n },\n }),\n );\n }\n\n getTemplate(templateId: string): Observable {\n return this.conversationApiService.getMessageTemplate({ templateId: templateId }).pipe(\n catchError(() => {\n this.snackbarService.openErrorSnack('INBOX.SETTINGS.MESSAGE_TEMPLATES.LOAD_TEMPLATE_FAILED');\n return of(null);\n }),\n );\n }\n}\n"], "mappings": "uPAgBA,IAAaA,GAAe,IAAA,CAAtB,IAAOA,EAAP,MAAOA,CAAe,CAD5BC,aAAA,CAEmB,KAAAC,uBAAyBC,EAAOC,CAAsB,EACtD,KAAAC,gBAAkBF,EAAOG,CAAe,EAExC,KAAAC,gBAAkBJ,EAAOK,CAAsB,EAC/C,KAAAC,WAAaN,EAAOO,CAAgB,EAErDC,cAAcC,EAAgBC,EAAgB,CAC5C,OAAOC,EAAc,CAAC,KAAKP,gBAAiB,KAAKE,UAAU,CAAC,EAAEM,KAC5DC,EAAU,CAAC,CAACC,EAAgBC,CAAS,IAAK,CACxC,IAAMC,EAAqB,IAAIC,EAAmB,CAChDC,gBAAiBJ,EACbK,EAAsBC,sCACtBD,EAAsBE,gCAC1BC,sBAAuBR,GAAkBC,EAC1C,EAED,OAAO,KAAKhB,uBAAuBwB,oBACjC,IAAIC,EAA2B,CAC7BC,cAAe,CAAEhB,OAAQA,EAAQC,SAAUA,CAAQ,EACnDM,mBAAoBA,EACrB,CAAC,CAEN,CAAC,CAAC,CAEN,CAEMU,eAAeC,EAAyB,QAAAC,EAAA,sBAC5C,IAAMC,EAAK,MAAMC,EACfnB,EAAc,CAAC,KAAKP,gBAAiB,KAAKE,UAAU,CAAC,EAAEM,KACrDmB,EAAI,CAAC,CAACjB,EAAgBC,CAAS,IACtB,IAAIE,EAAmB,CAC5BC,gBAAiBJ,EACbK,EAAsBC,sCACtBD,EAAsBE,gCAC1BC,sBAAuBR,GAAkBC,EAC1C,CACF,CAAC,CACH,EAEH,MAAMe,EACJ,KAAK/B,uBAAuBiC,sBAAsB,CAChDL,SAAUA,EACVX,mBAAoBa,EACrB,CAAC,CAEN,GAEMI,OAAOC,EAAkB,QAAAN,EAAA,sBAC7B,OAAO,MAAME,EAAe,KAAK/B,uBAAuBoC,sBAAsB,CAAED,WAAYA,CAAU,CAAE,CAAC,CAC3G,GAEME,eAAeT,EAAyB,QAAAC,EAAA,sBAC5C,MAAME,EACJ,KAAK/B,uBAAuBsC,sBAAsB,CAChDV,SAAUA,EACVW,UAAW,CACTC,MAAO,CAAC,OAAQ,SAAS,GAE5B,CAAC,CAEN,GAEAC,YAAYN,EAAkB,CAC5B,OAAO,KAAKnC,uBAAuB0C,mBAAmB,CAAEP,WAAYA,CAAU,CAAE,EAAEtB,KAChF8B,EAAW,KACT,KAAKxC,gBAAgByC,eAAe,uDAAuD,EACpFC,EAAG,IAAI,EACf,CAAC,CAEN,yCAtEW/C,EAAe,wBAAfA,EAAegD,QAAfhD,EAAeiD,UAAAC,WADF,MAAM,CAAA,EAC1B,IAAOlD,EAAPmD,SAAOnD,CAAe,GAAA", "names": ["TemplateService", "constructor", "conversationApiService", "inject", "ConversationApiService", "snackbarService", "SnackbarService", "accountGroupId$", "ACCOUNT_GROUP_ID_TOKEN", "partnerId$", "PARTNER_ID_TOKEN", "listTemplates", "cursor", "pageSize", "combineLatest", "pipe", "switchMap", "accountGroupId", "partnerId", "subjectParticipant", "SubjectParticipant", "participantType", "GlobalParticipantType", "GLOBAL_PARTICIPANT_TYPE_ACCOUNT_GROUP", "GLOBAL_PARTICIPANT_TYPE_PARTNER", "internalParticipantId", "listMessageTemplate", "ListMessageTemplateRequest", "pagingOptions", "createTemplate", "template", "__async", "sb", "firstValueFrom", "map", "createMessageTemplate", "delete", "templateId", "deleteMessageTemplate", "updateTemplate", "updateMessageTemplate", "fieldMask", "paths", "getTemplate", "getMessageTemplate", "catchError", "openErrorSnack", "of", "factory", "\u0275fac", "providedIn", "_TemplateService"] }