Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {
QueueManager,
} from 'queue-manager';
import { SceneObject } from './scene-object';

//

Expand Down Expand Up @@ -233,11 +234,17 @@ export class DiscordBot extends EventTarget {
return
}

const scene = new SceneObject({
name: 'Discord Channel Conversation',
description: 'A conversation happening in a Discord channel.',
});

const conversation = new ConversationObject({
agent,
getHash: () => {
return `discord:channel:${channelId}`;
},
scene,
});

this.agent.conversationManager.addConversation(conversation);
Expand Down Expand Up @@ -279,11 +286,17 @@ export class DiscordBot extends EventTarget {
return
}

const scene = new SceneObject({
name: 'Discord Direct Message Conversation',
description: 'A conversation happening with a user on Discord.',
});

const conversation = new ConversationObject({
agent,
getHash: () => {
return `discord:dm:${userId}`;
},
scene,
});

this.agent.conversationManager.addConversation(conversation);
Expand Down Expand Up @@ -352,6 +365,7 @@ export class DiscordBot extends EventTarget {
username,
text,
channelId, // if there is no channelId, it's a DM
messageId,
// XXX discord channel/dm distinction can be made more explicit with a type: string field...
} = e.data;

Expand All @@ -367,6 +381,7 @@ export class DiscordBot extends EventTarget {
method: 'say',
args: {
text,
messageId,
},
};
const id = getIdFromUserId(userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react';
import { useContext, useEffect } from 'react';
import { useAgent, useAuthToken, useConversation } from 'react-agents';
import { Action, ConversationProvider, useAgent, useAuthToken, useConversation } from 'react-agents';
import type {
DiscordArgs,
DiscordProps,
PendingActionEvent,
} from '../../types';
import {
AppContext,
} from '../../context';
import dedent from 'dedent';
import { z } from 'zod';

export const Discord: React.FC<DiscordProps> = (props: DiscordProps) => {
const {
Expand Down Expand Up @@ -45,5 +49,53 @@ export const Discord: React.FC<DiscordProps> = (props: DiscordProps) => {
conversation,
]);

return null;
return (
<>
<ConversationProvider>
<Action
type="discordMessageReferenceReply"
description={dedent`
Use this Action:
- STRICTLY WITHIN A DISCORD CHANNEL OR DIRECT MESSAGE (DM) SCENE, IF NO SCENE IS PROVIDED OR THE SCENE IS NOT A DISCORD CHANNEL OR DIRECT MESSAGE (DM), THE ACTION MUST NOT BE EXECUTED.
- To refer back to a specific message in the chat history or when replying to a message where you were specifically tagged using '@<your-discord-id>'.

Ensure the response is contextually relevant to the message being referenced or replied to.
`}
schema={
z.object({
messageReference: z.string(),
content: z.string(),
})
}
examples={[
{
messageReference: '1234567890',
content: 'Yes, I understand your point.',
},
]}
handler={
async (e: PendingActionEvent) => {
const {
message,
agent,
} = e.data;

const {
messageReference,
content,
} = message.args;

const replyMessage = {
content: content,
reply: {
messageReference: messageReference,
}
}
await agent.say(replyMessage);
}
}
/>
</ConversationProvider>
</>
);
};