MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / processMessage

Function processMessage

packages/weixin/src/monitor.ts:216–305  ·  view source on GitHub ↗
(
  msg: WeixinMessage,
  ctx: {
    baseUrl: string
    cdnBaseUrl: string
    token: string
    onMessage: OnMessageCallback
    onPermissionResponse?: OnPermissionResponseCallback
  },
)

Source from the content-addressed store, hash-verified

214}
215
216async function processMessage(
217 msg: WeixinMessage,
218 ctx: {
219 baseUrl: string
220 cdnBaseUrl: string
221 token: string
222 onMessage: OnMessageCallback
223 onPermissionResponse?: OnPermissionResponseCallback
224 },
225): Promise<void> {
226 if (msg.message_type !== MessageType.USER) return
227 const fromUserId = msg.from_user_id
228 if (!fromUserId) return
229
230 if (msg.context_token) {
231 contextTokens.set(fromUserId, msg.context_token)
232 }
233
234 if (!isAllowed(fromUserId)) {
235 const code = addPendingPairing(fromUserId)
236 try {
237 await sendText({
238 to: fromUserId,
239 text: `Your pairing code is: ${code}\n\nAsk the operator to confirm:\nccb weixin access pair ${code}`,
240 baseUrl: ctx.baseUrl,
241 token: ctx.token,
242 contextToken: msg.context_token || '',
243 })
244 } catch (error) {
245 process.stderr.write(`[weixin] Failed to send pairing code: ${error}\n`)
246 }
247 return
248 }
249
250 setActivePermissionChat(fromUserId, msg.context_token)
251
252 let textContent = ''
253 let mediaPath: string | undefined
254 let mediaType: string | undefined
255
256 if (msg.item_list) {
257 for (const item of msg.item_list) {
258 if (item.type === MessageItemType.TEXT && item.text_item?.text) {
259 textContent += `${textContent ? '\n' : ''}${item.text_item.text}`
260 } else if (
261 item.type === MessageItemType.IMAGE ||
262 item.type === MessageItemType.VOICE ||
263 item.type === MessageItemType.FILE ||
264 item.type === MessageItemType.VIDEO
265 ) {
266 const downloaded = await downloadMedia(item, ctx.cdnBaseUrl)
267 if (downloaded) {
268 mediaPath = downloaded.path
269 mediaType = downloaded.type
270 }
271 if (item.type === MessageItemType.VOICE && item.voice_item?.text) {
272 textContent += `${textContent ? '\n' : ''}[Voice transcription]: ${item.voice_item.text}`
273 }

Callers 1

startPollLoopFunction · 0.85

Calls 10

isAllowedFunction · 0.85
addPendingPairingFunction · 0.85
setActivePermissionChatFunction · 0.85
downloadMediaFunction · 0.85
extractPermissionReplyFunction · 0.85
consumePendingPermissionFunction · 0.85
setMethod · 0.80
sendTextFunction · 0.70
writeMethod · 0.45
onMessageMethod · 0.45

Tested by

no test coverage detected