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

Method postMessage

src/core/phelia.ts:93–148  ·  view source on GitHub ↗
(
    message: PheliaMessage<p>,
    channel: string,
    props: p = null,
    slackOptions?: ChatPostMessageArguments
  )

Source from the content-addressed store, hash-verified

91 }
92
93 async postMessage<p>(
94 message: PheliaMessage<p>,
95 channel: string,
96 props: p = null,
97 slackOptions?: ChatPostMessageArguments
98 ): Promise<string> {
99 const initializedState: { [key: string]: any } = {};
100
101 /** A hook to create some state for a component */
102 function useState<t>(
103 key: string,
104 initialValue?: t
105 ): [t, (value: t) => void] {
106 initializedState[key] = initialValue;
107 return [initialValue, (_: t): void => null];
108 }
109
110 /** A hook to create a modal for a component */
111 function useModal(): (title: string, props?: any) => Promise<void> {
112 return async () => null;
113 }
114
115 const messageData = await render(
116 React.createElement(message, { useState, props, useModal })
117 );
118
119 const {
120 channel: channelID,
121 ts,
122 message: sentMessageData,
123 } = await this.client.chat.postMessage({
124 ...messageData,
125 ...slackOptions,
126 channel,
127 });
128
129 const user = await this.enrichUser((sentMessageData as any).user);
130
131 const messageKey = `${channelID}:${ts}`;
132
133 await Phelia.Storage.set(
134 messageKey,
135 JSON.stringify({
136 message: JSON.stringify(messageData),
137 type: "message",
138 name: message.name,
139 state: initializedState,
140 user,
141 props,
142 channelID,
143 ts,
144 })
145 );
146
147 return messageKey;
148 }
149
150 async postEphemeral<p>(

Callers 1

server.tsFile · 0.80

Calls 2

enrichUserMethod · 0.95
renderFunction · 0.90

Tested by

no test coverage detected