Skip to content

Commit

Permalink
Update summarization responce to include permalink preview. (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
crspeller committed Dec 1, 2023
1 parent 33915e0 commit 380f7ef
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/post_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (p *Plugin) botDM(userID string, post *model.Post) error {
p.modifyPostForBot(userID, post)

if err := p.pluginAPI.Post.DM(p.botid, userID, post); err != nil {
return err
return errors.Wrap(err, "failed to post DM")
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ func (p *Plugin) startNewSummaryThread(postIDToSummarize string, context ai.Conv
return nil, err
}

siteURL := p.API.GetConfig().ServiceSettings.SiteURL
post := &model.Post{
Message: fmt.Sprintf("A summary of [this thread](/_redirect/pl/%s):\n", postIDToSummarize),
Message: fmt.Sprintf("Sure, I will summarize this thread: %s/_redirect/pl/%s\n", *siteURL, postIDToSummarize),
}
post.AddProp(ThreadIDProp, postIDToSummarize)

Expand Down
41 changes: 41 additions & 0 deletions webapp/src/components/llmbot_post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import PostText from './post_text';
import IconRegenerate from './assets/icon_regenerate';
import IconCancel from './assets/icon_cancel';

const PostMessagePreview = (window as any).Components.PostMessagePreview;

const FixPostHover = createGlobalStyle<{disableHover?: string}>`
${(props) => props.disableHover && css`
&&&& {
Expand Down Expand Up @@ -134,6 +136,19 @@ export const LLMBotPost = (props: Props) => {
};

const requesterIsCurrentUser = (props.post.props?.llm_requester_user_id === currentUserId);
const isThreadSummaryPost = (props.post.props?.referenced_thread && props.post.props?.referenced_thread !== '');

let permalinkView = null;
if (PostMessagePreview) { // Ignore permalink if version does not exporrt PostMessagePreview
const permalinkData = extractPermalinkData(props.post);
if (permalinkData !== null) {
permalinkView = (
<PostMessagePreview
metadata={permalinkData}
/>
);
}
}

return (
<PostBody
Expand All @@ -143,6 +158,11 @@ export const LLMBotPost = (props: Props) => {
onMouseMove={stopPropagationIfGenerating}
>
<FixPostHover disableHover={generating ? props.post.id : ''}/>
{isThreadSummaryPost && permalinkView &&
<>
{permalinkView}
</>
}
<PostText
message={message}
channelID={props.post.channel_id}
Expand All @@ -169,3 +189,24 @@ export const LLMBotPost = (props: Props) => {
</PostBody>
);
};

type PermalinkData = {
channel_display_name: string
channel_id: string
post_id: string
team_name: string
post: {
message: string
user_id: string
}
}

function extractPermalinkData(post: any): PermalinkData | null {
for (const embed of post?.metadata?.embeds || []) {
if (embed.type === 'permalink') {
return embed.data;
}
}
return null;
}

0 comments on commit 380f7ef

Please sign in to comment.