MCPcopy
hub / github.com/claude-code-best/claude-code / sendMediaFile

Function sendMediaFile

packages/weixin/src/send.ts:114–180  ·  view source on GitHub ↗
(params: {
  filePath: string
  to: string
  text: string
  baseUrl: string
  token: string
  contextToken: string
  cdnBaseUrl: string
})

Source from the content-addressed store, hash-verified

112}
113
114export async function sendMediaFile(params: {
115 filePath: string
116 to: string
117 text: string
118 baseUrl: string
119 token: string
120 contextToken: string
121 cdnBaseUrl: string
122}): Promise<{ messageId: string }> {
123 const mediaType = guessMediaType(params.filePath)
124 const uploaded = await uploadFile({
125 filePath: params.filePath,
126 toUserId: params.to,
127 mediaType,
128 apiBaseUrl: params.baseUrl,
129 token: params.token,
130 cdnBaseUrl: params.cdnBaseUrl,
131 })
132
133 const cdnMedia: CDNMedia = {
134 encrypt_query_param: uploaded.encryptQueryParam,
135 aes_key: uploaded.aesKey,
136 encrypt_type: 1,
137 }
138
139 const items: MessageItem[] = []
140 if (params.text) {
141 items.push({
142 type: MessageItemType.TEXT,
143 text_item: { text: markdownToPlainText(params.text) },
144 })
145 }
146
147 switch (mediaType) {
148 case 1:
149 items.push({
150 type: MessageItemType.IMAGE,
151 image_item: { media: cdnMedia, mid_size: uploaded.fileSize },
152 })
153 break
154 case 2:
155 items.push({
156 type: MessageItemType.VIDEO,
157 video_item: { media: cdnMedia, video_size: uploaded.fileSize },
158 })
159 break
160 default:
161 items.push({
162 type: MessageItemType.FILE,
163 file_item: {
164 media: cdnMedia,
165 file_name: uploaded.fileName,
166 len: String(uploaded.rawSize),
167 },
168 })
169 break
170 }
171

Callers 1

createWeixinMcpServerFunction · 0.85

Calls 5

guessMediaTypeFunction · 0.85
markdownToPlainTextFunction · 0.85
sendItemsFunction · 0.85
uploadFileFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected