Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3365793
D13782.id45364.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13782.id45364.diff
View Options
diff --git a/keyserver/src/responders/farcaster-webhook-responders.js b/keyserver/src/responders/farcaster-webhook-responders.js
--- a/keyserver/src/responders/farcaster-webhook-responders.js
+++ b/keyserver/src/responders/farcaster-webhook-responders.js
@@ -2,10 +2,12 @@
import { createHmac } from 'crypto';
import type { $Request } from 'express';
+import invariant from 'invariant';
import { getRustAPI } from 'rust-node-addon';
import bots from 'lib/facts/bots.js';
import { extractKeyserverIDFromID } from 'lib/keyserver-conn/keyserver-call-utils.js';
+import { messageTypes } from 'lib/types/message-types-enum.js';
import { threadTypes } from 'lib/types/thread-types-enum.js';
import { type NewThreadResponse } from 'lib/types/thread-types.js';
import { neynarWebhookCastCreatedEventValidator } from 'lib/types/validators/farcaster-webhook-validators.js';
@@ -17,6 +19,7 @@
createOrUpdateFarcasterChannelTag,
farcasterChannelTagBlobValidator,
} from '../creators/farcaster-channel-tag-creator.js';
+import createMessages from '../creators/message-creator.js';
import { createThread } from '../creators/thread-creator.js';
import { fetchThreadInfos } from '../fetchers/thread-fetchers.js';
import { verifyUserIDs } from '../fetchers/user-fetchers.js';
@@ -32,6 +35,55 @@
const noChannelCommunityID = '80887273';
const { commbot } = bots;
+async function createCastSidebar(
+ castHash: string,
+ parentHash: ?string,
+ channelName: ?string,
+ channelCommunityID: string,
+): Promise<?NewThreadResponse> {
+ let sidebarCastHash = castHash;
+ if (parentHash) {
+ sidebarCastHash = parentHash;
+ }
+
+ const sidebarCast =
+ await neynarClient?.fetchFarcasterCastByHash(sidebarCastHash);
+
+ if (!sidebarCast) {
+ return null;
+ }
+
+ const castAuthor = sidebarCast.author.username;
+ const channelText = channelName ? `\nin channel ${channelName}` : '';
+ const messageText = `${castAuthor} said ${sidebarCast.text}${channelText}`;
+ const commbotViewer = createBotViewer(commbot.userID);
+
+ const [{ id: messageID }] = await createMessages(commbotViewer, [
+ {
+ type: messageTypes.TEXT,
+ threadID: channelCommunityID,
+ creatorID: commbot.userID,
+ time: Date.now(),
+ text: messageText,
+ },
+ ]);
+
+ invariant(
+ messageID,
+ 'message returned from createMessages always has ID set',
+ );
+ const sidebarName =
+ messageText.length > 32 ? messageText.slice(0, 32) : messageText;
+ const response = await createThread(commbotViewer, {
+ type: threadTypes.SIDEBAR,
+ parentThreadID: channelCommunityID,
+ name: sidebarName,
+ sourceMessageID: messageID,
+ });
+
+ return response;
+}
+
async function createTaggedFarcasterCommunity(
channelID: string,
taggerFID: string,
@@ -179,7 +231,19 @@
throw new ServerError('blob_fetch_failed');
}
}
- console.log(channelCommunityID);
+
+ const sidebarThreadResponse = await createCastSidebar(
+ event.data.hash,
+ event.data.parent_hash,
+ event.data.channel?.name,
+ channelCommunityID,
+ );
+
+ if (!sidebarThreadResponse) {
+ return;
+ }
+
+ console.log(sidebarThreadResponse);
}
export { taggedCommFarcasterResponder, taggedCommFarcasterInputValidator };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 7:46 AM (21 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2583924
Default Alt Text
D13782.id45364.diff (3 KB)
Attached To
Mode
D13782: [keyserver] create message and sidebar based on cast
Attached
Detach File
Event Timeline
Log In to Comment