# 通过API自定义PM模板？

**URL:** https://meta.discourse.org/t/custom-template-for-pm-via-api/322585
**Category:** Development
**Tags:** email, rest-api
**Created:** [2024年八月20日 22:18 UTC](https://meta.discourse.org/t/custom-template-for-pm-via-api/322585 "2024-08-20T22:18:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BrianGillespie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/briangillespie/32/105563_2.png) [@BrianGillespie](https://meta.discourse.org/u/BrianGillespie)
#### Post date: [2024年八月20日 22:18 UTC](https://meta.discourse.org/t/custom-template-for-pm-via-api/322585/1 "2024-08-20T22:18:30Z")

</div>

您好，我们正在构建一个系统，用于在我们的软件崩溃时联系用户，并考虑通过 API 使用 [Discourse as a private email support portal](https://meta.discourse.org/t/discourse-as-a-private-email-support-portal/34444) 和 [https://meta.discourse.org/t/start-a-new-conversation-with-a-customer-not-yet-in-discourse/43876。](https://meta.discourse.org/t/start-a-new-conversation-with-a-customer-not-yet-in-discourse/43876%E3%80%82)

当我通过 API 发送电子邮件时，它似乎使用了内置模板之一，并在主题前加上 `[McNeel Forum] [PM]`。虽然这对其他私信用途来说是合理的，但我担心不在论坛上的用户会觉得这令人困惑，甚至可能是垃圾邮件。

有没有办法在通过 API 发送时指定自定义模板？我在以下位置找不到：

> **[Discourse API Docs](https://docs.discourse.org/#tag/Posts/operation/createTopicPostPM)**

这里有一个类似的未回答的问题：

> [@Private Message Send API](https://meta.discourse.org/t/private-message-send-api/27593/18):
>
> What if you use an email template as a message? I am going to the email\_templates endpoint, grabbing the template I want, then send that as a private message. However, none of the strings are replaced in the message to the user. The message contains %{site\_name} and ${base\_url} inside the message text. Just wondering how/when in the flow does Discourse substitute these (I couldn’t find any evidence).

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2024年八月20日 23:34 UTC](https://meta.discourse.org/t/custom-template-for-pm-via-api/322585/2 "2024-08-20T23:34:23Z")

</div>

您可以自定义该[在 Discourse 中自定义文本](https://meta.discourse.org/t/customize-text-in-discourse/36092)的文本，但不能为 API 和前端设置不同的文本。如果您需要不同的文本，则需要一个插件。

---

<div class="post-metadata">

### Author: ![BrianGillespie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/briangillespie/32/105563_2.png) [@BrianGillespie](https://meta.discourse.org/u/BrianGillespie)
#### Post date: [2024年八月21日 01:56 UTC](https://meta.discourse.org/t/custom-template-for-pm-via-api/322585/3 "2024-08-21T01:56:40Z")

</div>

感谢您提供有关自定义文本的参考。理想情况下，我们希望从 API 获取不同的文本 - 是否已有用于此目的的插件？ 谢谢

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2024年八月21日 09:13 UTC](https://meta.discourse.org/t/custom-template-for-pm-via-api/322585/4 "2024-08-21T09:13:19Z")

</div>

不。API 是前端完成所有工作的方式。API 和用户体验之间没有区别。

您需要一个插件来创建一个新的端点或接受一个参数来更改主题。
