-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contentful): WIP new Handoff content
- Loading branch information
Showing
5 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/botonic-plugin-contentful/src/contentful/contents/handoff.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as contentful from 'contentful' | ||
|
||
import * as cms from '../../cms' | ||
import { CmsException, ContentType, OnFinish, OnFinishPayload } from '../../cms' | ||
import { DeliveryApi } from '../delivery-api' | ||
import { | ||
addCustomFields, | ||
CommonEntryFields, | ||
ContentfulEntryUtils, | ||
} from '../delivery-utils' | ||
import { DeliveryWithFollowUp } from './follow-up' | ||
|
||
export class HandoffDelivery extends DeliveryWithFollowUp { | ||
constructor(delivery: DeliveryApi, resumeErrors: boolean) { | ||
super(ContentType.HANDOFF, delivery, resumeErrors) | ||
} | ||
|
||
async handoff(id: string, context: cms.Context): Promise<cms.Handoff> { | ||
const entry: contentful.Entry<HandoffFields> = await this.getEntry( | ||
id, | ||
context | ||
) | ||
return this.fromEntry(entry, context) | ||
} | ||
|
||
onFinish(entry: contentful.Entry<HandoffFields>): OnFinish { | ||
if (entry.fields.onFinishPayload && entry.fields.onFinishPath) { | ||
throw new CmsException( | ||
`${this.getContentIdForLogs(entry)} has both path and payload` | ||
) | ||
} else if (entry.fields.onFinishPayload) { | ||
return new OnFinishPayload(entry.fields.onFinishPayload) | ||
} else if (entry.fields.onFinishPath) { | ||
return new OnFinishPayload(entry.fields.onFinishPath) | ||
} | ||
throw new CmsException( | ||
`${this.getContentIdForLogs(entry)} has neither path nor payload` | ||
) | ||
} | ||
|
||
async fromEntry( | ||
entry: contentful.Entry<HandoffFields>, | ||
context: cms.Context | ||
): Promise<cms.Handoff> { | ||
const fields = entry.fields | ||
const common = ContentfulEntryUtils.commonFieldsFromEntry(entry) | ||
return addCustomFields( | ||
new cms.Handoff( | ||
common, | ||
fields.text, | ||
this.onFinish(entry), | ||
this.destination(entry), | ||
fields.shadowing | ||
), | ||
fields, | ||
['onFinishPath', 'onFinishPayload', 'queue', 'agentEmail', 'agendId'] | ||
) | ||
} | ||
} | ||
|
||
export interface HandoffFields extends CommonEntryFields { | ||
handoff: contentful.Asset | ||
} | ||
|
||
export interface HandoffFields extends CommonEntryFields { | ||
text: string | ||
queue?: string | ||
agentEmail?: string | ||
agentId?: string | ||
onFinishPath?: string | ||
onFinishPayload?: string | ||
shadowing?: boolean | ||
} |