@rhizogrip/spore-plugin-telegram 0.6.0 → 0.6.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
@@ -67,7 +67,7 @@ says so in your `working…` message, and the next turn answers it.
67
67
 
68
68
  ```
69
69
  /status what the spore is doing, its turns and what they cost, and the running turn's limits
70
- /stop end the turn it is running
70
+ /stop end the turn it is running, and set aside what you sent that it had not read
71
71
  /wrap [10m] ask the running turn to wrap up, now or in a while
72
72
  /extend wall 30m give it more — wall, cost or rounds — up to the extend.<limit> its spore.cmk grants
73
73
  ```
@@ -104,7 +104,7 @@ timed, a command that exited non-zero given its exit code, a call that failed ma
104
104
  machine, and a command line or a path is yours. A chat can ask for the calls themselves:
105
105
 
106
106
  ```json
107
- { "token": "${MAIN_BOT_TOKEN}", "chats": { "51168024": { "spore": "main", "details": true } } }
107
+ { "token": "${TRIAGE_BOT_TOKEN}", "chats": { "148392011": { "spore": "triage", "details": true } } }
108
108
  ```
109
109
 
110
110
  It is then shown `reading data/report.md`, `running git log --oneline -5`,
@@ -112,8 +112,8 @@ It is then shown `reading data/report.md`, `running git log --oneline -5`,
112
112
  read the commands; the others keep the kinds.
113
113
 
114
114
  A chat can be shown a turn more quietly, which is what a group gets unless its entry says
115
- otherwise: `"show": "react"` puts a 🫡 on your message when the spore takes it and shows Telegram's
116
- `typing…` while the turn runs, then takes the 🫡 off when the answer arrives — or puts a 💔 there
115
+ otherwise: `"show": "react"` puts a 👨‍💻 on your message when the spore takes it and shows Telegram's
116
+ `typing…` while the turn runs, then takes the 👨‍💻 off when the answer arrives — or puts a 💔 there
117
117
  when the turn ended without one. `"show": "working"` is the `working…` message, what a private
118
118
  chat gets; `"show": "both"` is both. The bot's two emoji are its own to choose, from the ones
119
119
  Telegram lets a bot react with (✅ and ❌ are not among them; the log lists them when one is refused):
@@ -133,7 +133,9 @@ refused chat 148392011 (@alice) — to allow it, add "148392011": "<a spore>" to
133
133
  ```
134
134
 
135
135
  which is also how you learn your own chat id: start with `"chats": {}` and message the bot. A
136
- group's id is negative, and it is the group you add rather than the people in it.
136
+ group's id is negative, and it is the group you add rather than the people in it. Where a spore's
137
+ `replyTo` default is one of this bot's chats, that chat is told the same line, once per chat the
138
+ file does not name, so you hear of someone trying the bot without reading its log.
137
139
 
138
140
  ## What it keeps
139
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizogrip/spore-plugin-telegram",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Telegram for spores: a bot of yours in chats, each chat reaching its spore, run as a service",
5
5
  "author": {
6
6
  "name": "Christophe Le Bars",
@@ -31,13 +31,13 @@
31
31
  "marked": "^18.0.11"
32
32
  },
33
33
  "peerDependencies": {
34
- "@rhizogrip/spore": "^1.18.0"
34
+ "@rhizogrip/spore": "^1.19.0"
35
35
  },
36
36
  "scripts": {
37
37
  "test": "vitest run"
38
38
  },
39
39
  "spore": {
40
- "works": "^1.18.0",
40
+ "works": "^1.19.0",
41
41
  "services": {
42
42
  "telegram": {
43
43
  "what": "a bot of yours in Telegram chats, each chat reaching its spore",
package/src/adapter.js CHANGED
@@ -25,6 +25,9 @@ const REACTIONS = [
25
25
  '🤷', '🤷‍♀', '😡'
26
26
  ]
27
27
 
28
+ const FIELDS = ['token', 'chats', 'react']
29
+ const CHAT_FIELDS = ['spore', 'details', 'show']
30
+
28
31
  const said = (err) => [err.message, err.detail].filter(Boolean).join(' — ')
29
32
 
30
33
  const invalid = (path, problem, detail) => new SporeError(`${path} ${problem}`, { type: 'TELEGRAM_BOT_INVALID', detail })
@@ -42,8 +45,12 @@ function routes (raw, path) {
42
45
  const table = new Map()
43
46
  for (const [chat, entry] of Object.entries(raw.chats)) {
44
47
  const spore = typeof entry === 'string' ? entry : entry?.spore
45
- const extra = typeof entry === 'object' && entry !== null ? Object.keys(entry).filter(key => !['spore', 'details', 'show'].includes(key)) : []
46
- if (typeof spore !== 'string' || !spore || extra.length || (typeof entry === 'object' && entry.details !== undefined && typeof entry.details !== 'boolean')) {
48
+ const extra = typeof entry === 'object' && entry !== null ? Object.keys(entry).filter(key => !CHAT_FIELDS.includes(key)) : []
49
+ if (extra.length) {
50
+ const bots = extra.filter(key => FIELDS.includes(key))
51
+ throw invalid(path, `gives chat ${chat} ${extra.join(', ')}, which a chat does not take`, `a chat takes ${CHAT_FIELDS.join(', ')}${bots.length ? `; ${bots.join(', ')} is the bot's, beside chats` : ''}`)
52
+ }
53
+ if (typeof spore !== 'string' || !spore || (typeof entry === 'object' && entry.details !== undefined && typeof entry.details !== 'boolean')) {
47
54
  throw invalid(path, `maps ${chat} to something that is not a spore`, 'each chat is a chat id against the name of a spore it may reach, or { "spore": "<name>", "details": true, "show": "react" }')
48
55
  }
49
56
  table.set(chat, { spores: [spore], details: typeof entry === 'object' && entry.details === true, show: typeof entry === 'object' ? entry.show ?? null : null })
@@ -51,13 +58,13 @@ function routes (raw, path) {
51
58
  return table
52
59
  }
53
60
 
54
- const HELP = 'Anything you write here goes to the spore. /status says what it is doing; /stop ends the turn it is running; /wrap [10m] asks it to wrap up; /extend wall 30m gives it more, as far as its spore.cmk allows.'
61
+ const HELP = 'Anything you write here goes to the spore. /status says what it is doing; /stop ends the turn it is running and sets aside what you sent that it had not read; /wrap [10m] asks it to wrap up; /extend wall 30m gives it more, as far as its spore.cmk allows.'
55
62
 
56
63
  export const TELEGRAM = {
57
64
  kind: 'telegram',
58
65
  label: 'Telegram',
59
66
  noun: 'chat',
60
- fields: ['token', 'chats', 'react'],
67
+ fields: FIELDS,
61
68
  credentials: ['token'],
62
69
  stateFields: [],
63
70
  sourceVariables: [],