MCPcopy Index your code
hub / github.com/simstudioai/sim / buildMessageContent

Function buildMessageContent

apps/sim/tools/linq/utils.ts:46–89  ·  view source on GitHub ↗
(input: MessageContentInput)

Source from the content-addressed store, hash-verified

44 * on optional effect, reply, service preference, and idempotency fields.
45 */
46export function buildMessageContent(input: MessageContentInput): Record<string, unknown> {
47 const parts: Array<Record<string, unknown>> = []
48
49 if (input.linkUrl) {
50 // Linq requires a link to be the only part in a message — it cannot be
51 // combined with text or media parts — so a link is sent on its own.
52 parts.push({ type: 'link', value: input.linkUrl })
53 } else {
54 if (input.text && input.text.length > 0) {
55 parts.push({ type: 'text', value: input.text })
56 }
57 if (input.attachmentId) {
58 parts.push({ type: 'media', attachment_id: input.attachmentId })
59 } else if (input.mediaUrl) {
60 parts.push({ type: 'media', url: input.mediaUrl })
61 }
62 }
63
64 if (parts.length === 0) {
65 throw new Error('A message requires text, a media URL, an attachment ID, or a link URL')
66 }
67
68 const message: Record<string, unknown> = { parts }
69
70 if (input.preferredService) {
71 message.preferred_service = input.preferredService
72 }
73 if (input.effectName || input.effectType) {
74 const effect: Record<string, unknown> = {}
75 if (input.effectName) effect.name = input.effectName
76 if (input.effectType) effect.type = input.effectType
77 message.effect = effect
78 }
79 if (input.replyToMessageId) {
80 const replyTo: Record<string, unknown> = { message_id: input.replyToMessageId }
81 if (typeof input.replyToPartIndex === 'number') replyTo.part_index = input.replyToPartIndex
82 message.reply_to = replyTo
83 }
84 if (input.idempotencyKey) {
85 message.idempotency_key = input.idempotencyKey
86 }
87
88 return message
89}
90
91/** Map a raw webhook subscription API object to the camelCase output shape. */
92export function mapWebhookSubscription(data: Record<string, unknown>): LinqWebhookSubscription {

Callers 2

send_message.tsFile · 0.90
create_chat.tsFile · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected