# Discourse-automation не отправил ЛС: нет допустимых получателей

**URL:** https://meta.discourse.org/t/discourse-automation-did-not-send-pm-no-valid-targets-exist/395740
**Category:** Bug
**Tags:** automation
**Created:** [11.Февраль.2026 04:16:17 UTC](https://meta.discourse.org/t/discourse-automation-did-not-send-pm-no-valid-targets-exist/395740 "2026-02-11T04:16:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![pangbo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pangbo/32/538562_2.png) [@pangbo](https://meta.discourse.org/u/pangbo)
#### Post date: [11.Февраль.2026 04:16:17 UTC](https://meta.discourse.org/t/discourse-automation-did-not-send-pm-no-valid-targets-exist/395740/1 "2026-02-11T04:16:17Z")

</div>

![image](https://global.discourse-cdn.com/meta/original/4X/2/2/f/22fa10422b1f9eb8639037357c995e76f1a87f51.png)

В логах я заметил предупреждения о том, что плагин discourse-automation не смог отправить личные сообщения. Плагин автоматизации использует имена пользователей на момент срабатывания триггера, а не актуальные имена пользователей на момент отправки ЛС. Поскольку скрипт отправки личных сообщений поддерживает отложенную отправку, пользователи могут сменить свои имена после срабатывания триггера, но до отправки сообщения, что приводит к ошибкам.

Я считаю, что изменение `DiscourseAutomation::PendingPm` для записи идентификаторов пользователей вместо имён пользователей может решить эту проблему:

> <https://github.com/discourse/discourse/blob/d10b6be86f5a0184c4551f1eb5ee0cef22ba94dc/plugins/automation/app/models/discourse_automation/pending_pm.rb#L14-L26>

* * *

Что касается моего случая использования:

У меня есть задача отправлять личные сообщения новым пользователям с задержкой. Я настроил плагин автоматизации на отправку ЛС через пять минут после вступления пользователей в группу TL0. Однако некоторые новые пользователи сразу же после регистрации меняют свои имена, что приводит к ошибкам отправки.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [11.Февраль.2026 06:04:53 UTC](https://meta.discourse.org/t/discourse-automation-did-not-send-pm-no-valid-targets-exist/395740/2 "2026-02-11T06:04:53Z")

</div>

Это удивительно хитрая кроличья нора, которая уходит довольно глубоко.

Когда вы закончите копать, вы обнаружите, что фундаментальная конструкция, которую мы имели — `PostCreator` — никогда не поддерживала идентификаторы пользователей.

> <https://github.com/discourse/discourse/pull/37708>
>
> Add \`target\_user\_ids\` as an alternative to \`target\_usernames\` when
> creating priv…ate messages via PostCreator and TopicCreator. The two
> options are mutually exclusive and raise ArgumentError if both are
> provided.
> 
> This avoids username-based lookups where the caller already has user
> IDs, and prevents stale references when users rename after a pending
> PM is created.
> 
> Key changes:
> \- PostCreator/TopicCreator: accept \`target\_user\_ids\`, validate
> mutual exclusivity with \`target\_usernames\`, extract shared
> \`add\_users\_from\_scope\` in TopicCreator
> \- Automation PendingPm: migrate from \`sender\`/\`target\_usernames\`
> string columns to \`sender\_id\`/\`target\_user\_ids\` integer columns
> with a backfill migration
> \- Scriptable::Utils.send\_pm: resolve sender upfront, support
> integer sender param, store IDs in pending PMs

Я думаю, что это отличное изменение, потому что всё становится гораздо менее неожиданным. Пользователи склонны немного менять свои имена пользователей, когда только начинают.
