MCPcopy Create free account
hub / github.com/deta/surf / parseMessage

Method parseMessage

packages/web-parser/src/sites/slack.ts:144–183  ·  view source on GitHub ↗
(node: Element)

Source from the content-addressed store, hash-verified

142 }
143
144 parseMessage(node: Element) {
145 const rawMessageId = node.parentElement?.getAttribute('data-item-key')
146 if (!rawMessageId) {
147 console.log('No message id found')
148 return null
149 }
150
151 const messageId = this.parseMessageID(rawMessageId)
152 console.log('Message ID', messageId)
153
154 const timestamp = this.parseRawMessageIDIntoTimestamp(rawMessageId)
155 const sender = this.getMessageSender(node)
156
157 const channel = this.getChannel()
158 const messageUrl = this.getMessageUrl(node)
159 const authorUrl = sender?.id && messageUrl ? this.parseAuthorURL(messageUrl, sender.id) : null
160
161 const contentElem = this.getMessageContentElem(node)
162 if (!contentElem) {
163 console.log('No message content found')
164 return null
165 }
166
167 const message = {
168 messageId: messageId,
169 url: messageUrl,
170 content: contentElem.textContent ?? '',
171 contentHtml: contentElem.innerHTML,
172 date_published: timestamp,
173 date_edited: null,
174 author: sender?.name ?? null,
175 author_fullname: sender?.name ?? null,
176 author_image: sender?.image ?? null,
177 author_url: authorUrl,
178 channel: channel?.name ?? null,
179 channel_url: channel?.url ?? null
180 }
181
182 return message as SlackMessageData
183 }
184
185 getMessages(parent: Element | Document) {
186 const messageNodes = this.getMessageContainers(parent)

Callers 2

getMessagesMethod · 0.95
handleClickMethod · 0.95

Calls 8

parseMessageIDMethod · 0.95
getMessageSenderMethod · 0.95
getChannelMethod · 0.95
getMessageUrlMethod · 0.95
parseAuthorURLMethod · 0.95
getMessageContentElemMethod · 0.95
logMethod · 0.80

Tested by

no test coverage detected