@rhizogrip/spore-plugin-teams 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -83,8 +83,9 @@ it mentions the bot, and the mention is not part of what the spore is told; the
83
83
  wrote and where. The bot posts `working…` and shows what kind of call runs as it runs; the answer
84
84
  is a new message — in a channel, in the thread of the message it answers — and `working…` is then
85
85
  removed, or marked `answered below` where Teams will not remove it; in a channel thread, Teams shows
86
- `This message has been deleted.` where it was. The answer is sent as Teams
87
- markdown. What the turn left in `data/out/` is named, one line a file: files do not cross yet,
86
+ `This message has been deleted.` where it was. The answer is sent in Teams' extended Markdown,
87
+ so tables and fenced code render; what the bot says itself — status, notices — is plain text,
88
+ line for line. What the turn left in `data/out/` is named, one line a file: files do not cross yet,
88
89
  either way.
89
90
 
90
91
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizogrip/spore-plugin-teams",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Microsoft Teams for spores: a bot of yours in personal chats and channels, each reaching its spore, run as a service",
5
5
  "author": {
6
6
  "name": "Christophe Le Bars",
package/src/adapter.js CHANGED
@@ -162,6 +162,8 @@ export function normalize (activity) {
162
162
  }
163
163
  }
164
164
 
165
+ const escapeHtml = (text) => text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
166
+
165
167
  const tenantOf = (activity) => activity.conversation?.tenantId ?? activity.channelData?.tenant?.id
166
168
 
167
169
  /** Whether anything in a card, however deep — an action set, a select action, a refresh — sends a press back to the bot. */
@@ -250,10 +252,15 @@ export function createAdapter ({ connector, receive, app, tenant }) {
250
252
  return { conversation: note.slice(0, at), id: note.slice(at + 1) }
251
253
  }
252
254
 
255
+ /**
256
+ * An answer in Teams' extended Markdown, which renders the tables and fenced code a model writes;
257
+ * what the relay says itself in Teams' HTML subset, escaped, each line on its own — its plain
258
+ * format runs lines together.
259
+ */
253
260
  const activity = (text, { markdown = false, answering = null } = {}) => ({
254
261
  type: 'message',
255
- text,
256
- textFormat: markdown ? 'markdown' : 'plain',
262
+ text: markdown ? text : escapeHtml(text).replace(/\n/g, '<br>'),
263
+ textFormat: markdown ? 'extendedmarkdown' : 'xml',
257
264
  ...(answering === null ? {} : { replyToId: answering })
258
265
  })
259
266