(
message: PheliaMessage<p>,
channel: string,
props: p = null,
slackOptions?: ChatPostMessageArguments
)
| 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>( |
no test coverage detected