Commit 4cae1c5
committed
feat(n8n): propagate originating-conversation routing into workflow generator
When the workflow is generated from inside a platform conversation
(e.g. a Discord DM or a Telegram chat), surface the originating channel
or chat to the LLM as a `## Runtime Facts` line so the user can say
"post the result back to this channel" and the generated send node
targets the right ID without naming it.
End-to-end wiring:
- `client-types-chat.ts`: extend `N8nWorkflowGenerateRequest` with
optional `bridgeConversationId`. AutomationsView already had the id
in scope (it uses it to bind the workflow to the originating
conversation); now also forwards it on the generation request.
- `n8n-routes.ts`: when `bridgeConversationId` is present, read the
originating conversation's tail inbound message metadata via
`runtime.getMemories({ roomId, tableName: "messages", count: 12 })`,
derive a `TriggerContext` (Discord channelId/guildId, Telegram
chatId/threadId, Slack channelId/teamId), and thread it into
`service.generateWorkflowDraft(prompt, { triggerContext })`. The
helper reads BOTH the canonical `metadata.discord.{channelId,guildId}`
sub-object AND the legacy flat `discordChannelId` / `discordServerId`
fields — pre-existing schema gap; canonical wins when present, flat
is the fallback so nothing today breaks.
- `n8n-runtime-context-provider.ts`: extend `RuntimeContextProviderInput`
to accept the trigger context, render it as a fact line:
This workflow was prompted from a Discord conversation in
#general (id 9876543210) within "Cozy Devs" (id 1234567890).
When the user references "this channel" or "back to here",
target that channel ID.
Same pattern for Telegram chats and Slack channels. Empty / missing
routing data → no fact line.
Backward compatibility:
- Routes still work without `bridgeConversationId` (no triggerContext
threading, baseline behavior).
- Plugin still works with hosts that don't pass triggerContext (the
optional `opts` arg on `generateWorkflowDraft` is unused — see
elizaos-plugins/plugin-n8n-workflow#26).
Out of scope (follow-up):
- Persist `originChannelContext` on the workflow's conversation metadata
for re-runs without a fresh inbound message.
- Switch upstream plugin-discord/telegram from flat metadata fields to
the canonical nested `metadata.discord.{channelId,guildId,messageId}`
shape.
Depends on: elizaos-plugins/plugin-n8n-workflow#26 (TriggerContext on
RuntimeContextProviderInput) at runtime; this PR's host code compiles
and falls through cleanly until the plugin upgrade is wired.1 parent cafdf62 commit 4cae1c5
4 files changed
Lines changed: 218 additions & 2 deletions
File tree
- packages/app-core/src
- api
- components/pages
- services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
508 | 516 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
610 | 610 | | |
611 | 611 | | |
612 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
613 | 749 | | |
614 | 750 | | |
615 | 751 | | |
| |||
1130 | 1266 | | |
1131 | 1267 | | |
1132 | 1268 | | |
| 1269 | + | |
1133 | 1270 | | |
1134 | 1271 | | |
1135 | 1272 | | |
1136 | | - | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
1137 | 1277 | | |
1138 | 1278 | | |
1139 | 1279 | | |
| |||
1158 | 1298 | | |
1159 | 1299 | | |
1160 | 1300 | | |
1161 | | - | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
1162 | 1309 | | |
1163 | 1310 | | |
1164 | 1311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4596 | 4596 | | |
4597 | 4597 | | |
4598 | 4598 | | |
| 4599 | + | |
4599 | 4600 | | |
4600 | 4601 | | |
4601 | 4602 | | |
| |||
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
98 | 115 | | |
99 | 116 | | |
100 | 117 | | |
101 | 118 | | |
| 119 | + | |
102 | 120 | | |
103 | 121 | | |
104 | 122 | | |
| |||
209 | 227 | | |
210 | 228 | | |
211 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
212 | 264 | | |
213 | 265 | | |
214 | 266 | | |
| |||
389 | 441 | | |
390 | 442 | | |
391 | 443 | | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
392 | 452 | | |
393 | 453 | | |
394 | 454 | | |
| |||
0 commit comments