@@ -81,6 +81,7 @@ import {
8181 ChannelMessage_Post_AttachmentSchema ,
8282 type AppMetadata ,
8383 StreamEvent ,
84+ ChannelMessage_Post_MentionSchema ,
8485} from '@towns-protocol/proto'
8586import {
8687 bin_equal ,
@@ -118,6 +119,7 @@ import { getSmartAccountFromUserIdImpl } from './smart-account'
118119import type { BotIdentityConfig , BotIdentityMetadata , ERC8004Endpoint } from './identity-types'
119120import channelsFacetAbi from '@towns-protocol/generated/dev/abis/Channels.abi'
120121import rolesFacetAbi from '@towns-protocol/generated/dev/abis/Roles.abi'
122+ import { EmptySchema } from '@bufbuild/protobuf/wkt'
121123
122124type BotActions = ReturnType < typeof buildBotActions >
123125
@@ -192,7 +194,9 @@ export type MessageOpts = {
192194}
193195
194196export type PostMessageOpts = MessageOpts & {
195- mentions ?: PlainMessage < ChannelMessage_Post_Mention > [ ]
197+ mentions ?: Array <
198+ { userId : string ; displayName : string } | { roleId : number } | { atChannel : true }
199+ >
196200 attachments ?: Array <
197201 | ImageAttachment
198202 | ChunkedMediaAttachment
@@ -1831,7 +1835,7 @@ const buildBotActions = (
18311835 value : {
18321836 body : message ,
18331837 attachments : processedAttachments . filter ( ( x ) => x !== null ) ,
1834- mentions : opts ?. mentions || [ ] ,
1838+ mentions : processMentions ( opts ?. mentions ) ,
18351839 } ,
18361840 } ,
18371841 } ,
@@ -1895,7 +1899,7 @@ const buildBotActions = (
18951899 case : 'text' ,
18961900 value : {
18971901 body : message ,
1898- mentions : opts ?. mentions || [ ] ,
1902+ mentions : processMentions ( opts ?. mentions ) ,
18991903 attachments : processedAttachments . filter ( ( x ) => x !== null ) ,
19001904 } ,
19011905 } ,
@@ -2440,3 +2444,37 @@ const parseMentions = (
24402444 ? [ { userId : m . userId , displayName : m . displayName } ]
24412445 : [ ] ,
24422446 )
2447+
2448+ const processMentions = (
2449+ mentions : PostMessageOpts [ 'mentions' ] ,
2450+ ) : PlainMessage < ChannelMessage_Post_Mention > [ ] => {
2451+ if ( ! mentions ) {
2452+ return [ ]
2453+ }
2454+ return mentions . map ( ( mention ) => {
2455+ if ( 'userId' in mention ) {
2456+ return create ( ChannelMessage_Post_MentionSchema , {
2457+ userId : mention . userId ,
2458+ displayName : mention . displayName ,
2459+ } )
2460+ } else if ( 'roleId' in mention ) {
2461+ return create ( ChannelMessage_Post_MentionSchema , {
2462+ mentionBehavior : {
2463+ case : 'atRole' ,
2464+ value : {
2465+ roleId : mention . roleId ,
2466+ } ,
2467+ } ,
2468+ } )
2469+ } else if ( 'atChannel' in mention ) {
2470+ return create ( ChannelMessage_Post_MentionSchema , {
2471+ mentionBehavior : {
2472+ case : 'atChannel' ,
2473+ value : create ( EmptySchema , { } ) ,
2474+ } ,
2475+ } )
2476+ } else {
2477+ throw new Error ( `Invalid mention type: ${ JSON . stringify ( mention ) } ` )
2478+ }
2479+ } )
2480+ }
0 commit comments