MCPcopy
hub / github.com/maxchehab/phelia / processSubmission

Method processSubmission

src/core/phelia.ts:635–831  ·  view source on GitHub ↗
(payload: any)

Source from the content-addressed store, hash-verified

633 }
634
635 async processSubmission(payload: any) {
636 const messageKey = payload.view.id;
637 const rawViewContainer = await Phelia.Storage.get(messageKey);
638
639 if (!rawViewContainer) {
640 throw new Error(
641 `Could not find Message Container with key ${messageKey} in storage.`
642 );
643 }
644
645 const viewContainer: PheliaMessageContainer = JSON.parse(rawViewContainer);
646
647 const rawInvokerContainer = await Phelia.Storage.get(
648 viewContainer.invokerKey
649 );
650
651 if (!rawInvokerContainer) {
652 throw new Error(
653 `Could not find Message Container with key ${viewContainer.invokerKey} in storage.`
654 );
655 }
656
657 const invokerContainer: PheliaMessageContainer = JSON.parse(
658 rawInvokerContainer
659 );
660
661 /** A hook to create some state for a component */
662 function useState<t>(
663 key: string,
664 initialValue?: t
665 ): [t, (value: t) => void] {
666 const [_, setState] = reactUseState(initialValue);
667
668 return [
669 invokerContainer.state[key],
670 (newValue: t): void => {
671 invokerContainer.state[key] = newValue;
672 setState(newValue);
673 },
674 ];
675 }
676
677 const executedCallbacks = new Map<string, boolean>();
678 const executionPromises = new Array<Promise<any>>();
679
680 /** Extracts content from modal form submission */
681 const formFromPayload = (payload: any) => {
682 if (payload.type === "view_submission") {
683 const form = Object.keys(payload.view.state.values)
684 .map((key) => [key, Object.keys(payload.view.state.values[key])[0]])
685 .map(([key, action]) => {
686 const data = payload.view.state.values[key][action];
687
688 if (data.type === "datepicker") {
689 return [action, data.selected_date];
690 }
691
692 if (

Callers 1

messageHandlerMethod · 0.95

Calls 1

renderFunction · 0.90

Tested by

no test coverage detected