使用 Zapier 自动发送 Discourse 邀请邮件

您可以使用 Discourse API 在外部应用程序上执行操作时,自动发送论坛邀请电子邮件。对于许多应用程序,您可以使用 Zapier 进行设置,而无需编写任何代码。

一个常见的用例是,当用户购买产品或在外部服务上注册时,邀请他们加入您的论坛。在本文的示例中,我将使用 Zapier WordPress 集成来触发在 WordPress 网站上有新用户注册时从 Discourse 发送邀请。

在 Zapier 上设置触发步骤

访问您的 Zapier 仪表板,搜索您想要触发邀请电子邮件的应用程序。在下面的截图中,我选择了 WordPress 作为触发器。

这里唯一需要的配置是连接 WordPress Zap 到一个 WordPress 账户,并选择“New User”事件来触发 Zap。

设置用于发送邀请的操作步骤

点击“Add a Step”按钮,然后从下拉菜单中点击“Action/Search”。

在搜索菜单中输入“webhook”,然后从操作菜单中选择“Webhooks by Zapier”。Webhook 操作步骤将添加到您的 Zap 侧边栏,并且会打开一个表单,让您选择希望 Webhook 执行哪种类型的请求。

从表单中选择 POST,然后点击 Continue。

打开的表单允许您配置发送到 Discourse 的 POST 请求。在 URL 字段中,输入您论坛的基础 URL,后跟 /invites。例如,我的论坛的基础 URL 是 https://demo.scossar.com,因此邀请路由的完整链接是 https://demo.scossar.com/invites

您现在需要配置表单的 Payload Type(负载类型)、Data(数据)和 Headers(标头)部分。所有其他表单部分可以保留默认值。

Payload Type 告诉 Zapier 以何种格式发送负载。它应设置为 Json

Data 部分用于告诉 Discourse 将邀请发送到哪个电子邮件地址,并设置可选的用户组列表和自定义消息。要邀请用户而不将其添加到用户组或包含自定义消息,输入 email 作为数据 Key,然后点击“Insert a Field”图标以打开字段的下拉菜单。向下滚动列表,直到看到包含用户电子邮件的触发应用传递的值。当使用 WordPress 作为触发应用时,完成的 Data 部分应如下所示:

要自动将用户添加到他们接受邀请时所在的组,请点击 Data 部分的 :heavy_plus_sign: 图标以添加一个新字段。将该字段的 Key 设置为 group_names。将该字段的值设置为您希望用户被添加到的组名的逗号分隔列表。要包含在邀请电子邮件中的自定义消息,创建一个新的字段,其 Key 设置为 custom_message,其值设置为您想要发送的消息。

注意:在 Zap 的触发步骤后添加一个 Code 步骤应该可以动态地为特定用户设置组名和自定义消息。

Headers 部分用于验证您的请求。要配置 Headers 字段,您需要在 Discourse 站点上生成一个 API 密钥。要执行此操作,请访问您的 Discourse 站点的 Admin / API 页面,然后点击“New API Key”按钮。创建密钥时,将其分配给一个工作人员用户,并将范围设置为 Global,或者使用 Granular 范围并勾选 Invites > Create 框。

现在,在 Zap 的 Headers 部分中,输入以下键/值对。用适合您站点的适当值替换我用方括号括起来的任何值。键的字母大小写很重要。

Api-Username: <您希望发送邀请的工作人员用户名>
Api-Key: <您生成的 API 密钥>
Content-Type: application/json

表单现在应该与下面的屏幕截图相似,但包含您的 Api-Username 和 Api-Key:

点击 Continue 按钮。

现在,您可以通过点击“Send Test To Webhooks by Zapier”按钮来测试集成。测试将使用您在触发步骤中设置的数据进行。如果一切配置正确,您将看到成功消息,并且您在触发步骤中设置的用户尚不存在于您的 Discourse 论坛上,将发送一封邀请电子邮件,并且您将在 Zapier 上看到一条 Success 消息。一旦测试步骤通过,点击 Finish 按钮并打开您的 Zap。

有关如何使用 Zapier 向 Discourse API 发送其他类型请求的详细信息,请参阅 https://meta.discourse.org/t/how-to-make-requests-to-the-discourse-api-with-zapier/122126。

25 个赞

This is awesome thank you for the feature and clear instructions!

Is it possible to also set the custom group when generating an invite, like you can from within the app?

That can be done by adding a group_names key to the Headers field. Its value should be set to a comma separated list of group names. I’ll add an example of this to the topic.

The basic approach that’s used in this topic will work for any API request to Discourse.

3 个赞

Awesome!! I think the dialog accepts a custom message too, guessing that can be done the same way?

1 个赞

I tried setting this up this AM and was running into a 400 error. With a little bit of debugging, I found that the auth-related steps need to go in the headers section as instructed, but the actual form values (email, group name, and custom message) need to go in the data section as key/value sets.

Once I made that change, though, it worked perfectly!

1 个赞

Thanks for that, @simon!

Are there any descriptions on meta about alternative ways to create an automated process for sending an invite email after the reader signed up to an offering and to which you could link here?

Thanks for testing that! What I’m finding is that when no custom_message or group_names are included in the request, passing the email in the Headers works. It’s not the correct way to pass the email address though. I’ve updated the guide to use the Data section for setting the email address, and have included examples for adding users to groups and including a custom message.

4 个赞

I’m not aware of other services that are similar to Zapier, but I’m sure there are some out there. You can make requests directly to the Discourse API without using a third party service. The main requirement for doing this is that you have an application to make the requests from. This can be something a simple as a WordPress site.

A good resource on Meta for getting started with the API is Reverse engineer the Discourse API. You can test API requests with CURL from your computer’s terminal, or with a service like Postman.

2 个赞

Thank you! Most of what you write I have no idea about… but I’ll check I’ll out your links and see if so can understand anything :smiley:

2 个赞

@simon

Quick question:

When I send an automated invite through Zapier, would this then be an already personalized link, or a link to the general login page to my forum (where someone can log in and also create an account)?

I would like to avoid that everybody and their dog who knows the login page creates an account. How can that best be avoided?

When you send an invite link through Zapier you are triggering exactly the same action as if you had clicked the ‘Send an Invite’ link from your account’s Invite page.

Creating an invite will send an email to invited user’s email address. That email contains a link to a page where the invited user can set their name and password, and login to their new account. The email address for the new account is set by the email address that you used for the invite.

Only users who have been sent an invite can create an account through this page. If you would like to only allow invited users to register for your site, go to the Login section of your Site Settings and select the invite only site setting.

The best way to get a sense of how invites work is to invite yourself to your site. You can use a throw-away gmail address for this. You will need to log out of the site before you will be able to accept your invite.

3 个赞

Ah, awesome info. Thanks!!

1 个赞

Thanks for the great tutorial! Is there a way to add a topic id that the user gets redirected to after signing up like in the bulk invite feature?

It is possible to invite a new user to a topic with a similar approach to what is outlined above, but the URL that you setup in the Action step needs to point to the topic. For example, to invite a user to a topic with the id 123 you would add the URL https://forum.example.com/t/123/invite to the Action step. You would then add the email and the optional custom_message and group_names parameters in the same way as they are outlined in the guide.

3 个赞

你好,Simon,

感谢你的帖子!

我有两个问题,如果你能帮我,那就太棒了:slight_smile:

问题 1:
在我这边,邀请链接加消息功能运行正常,但无论我添加哪些 group_names,加入论坛时我只能访问默认的公开群组。

你知道是否有某种情况会“阻止”对特定私有群组的邀请吗?

该群组的 URL 格式如下:https://forum.[mywebsite].com/c/cercle/33

因此,我设置的是:group_names /// PUBLIC,cercle

我也尝试用“数字”(即 33)代替群组名称,但依然不起作用。

这是否可能是因为论坛的管理员设置中存在某种“限制”,从而阻止了私有群组的邀请?

问题 2:

我希望能够邀请用户加入的不仅是“私有群组”,还有“私有子群组”(我不确定正确的术语是什么)。

如图所示,我有一个名为“RÉSERVÉ…"的群组,其下还有若干小规模的子群组。

我希望能够将用户邀请到特定的子群组中。

你知道该如何实现吗?

非常感谢你抽出时间帮助我!:slight_smile:

1 个赞

请确保你使用的是组的名称,而不是你允许该组访问的分类名称。你可以在组的 URL 中找到组名,或者在组的“名称”字段中查看:

如果这未能解决问题,请确保你在 Zapier 中添加的 Discourse API 密钥是全局的“所有用户”API 密钥。同时,请确保在 Zapier 中设置的 API 用户名具有将用户添加到组的权限。你网站上的任何管理员用户名都可以用于此目的。

如果问题仍未解决,请告诉我。

你可以通过在 Zapier 的 group_names 字段中添加以逗号分隔的组名列表,将用户邀请到多个组。Discourse 没有“子组”的概念,因此你需要添加每个你希望邀请用户加入的组的名称。

根据你提供的截图,看起来你试图让用户访问某个分类及其所有子分类。与其为每个子分类创建一个组,你只需允许一个组访问该分类及其所有子分类即可。这可以在分类编辑页面的“安全”部分进行配置。

2 个赞

谢谢你的回复,Simon!

关于 API 的问题:

我之前只授予了一个用户(管理员)访问权限,以为这样就可以了。所以我创建了一个新的 API,打算让所有用户都能访问。

但问题依然存在。不过,我可能已经理解出问题了:slight_smile

我试图在"group_names"字段中添加一个“类别”名称,所以我想这样是行不通的:)。

我误解了“组(group)”、“类别(category)”和“主题(topic)”这些名称的含义。

从截图中你可以看到大约 15 个子类别的列表:TB、MT、RD、MA 等。

例如,第一个子类别的 URL 是:https://forum.MYWEBSITE.com/c/question-formactions/TBD/14

所以我猜,我想自动邀请新成员加入某些私有子类别,而不是某个组。

在我提供的 URL 中,我希望只授予用户访问子类别"TBD"的权限,例如。

而另一位用户则只拥有访问另一个子类别的权限。

你知道这可以实现吗?

也许我只需要在 Zapier 中将"group_names"字段替换为对应的“类别”字段?

1 个赞

在 Discourse 中,群组和分类常常让人混淆!

  1. 群组是人员的集合。
  2. 分类是话题的集合。你无法直接邀请人员加入分类,但可以通过群组来控制对这些分类的访问权限。

要实现你的需求,请先创建一个群组。然后在相关分类的安全设置中,为该群组添加访问权限。最后,在邀请 API 中使用该群组即可。搞定。

3 个赞

谢谢你的回复,Nathan!

我会试试那个方法,然后把结果发在这里 :wink:

2 个赞

您的解决方案运行良好,谢谢!:smiley:

我还有另一个问题,也许您(或 @simon)能帮我解答:

在使用 Zapier 时,有没有办法为已经是 Discourse 成员的现有用户开放新组的访问权限?

基本上,我的工作流程如下:

1/ 一名成员加入我的某个课程

2/ Zapier 从我的学习平台获取他的邮箱,向他发送 Discourse 的邀请,并自动将他添加到与他刚加入的课程相关的正确群组中。

3/ 有时,几个月后,该成员会加入另一个课程:因此,按照我当前的流程,Zapier 会再次向他发送 Discourse 邀请,但他已经是成员了,所以该邀请无法生效。

我需要 Zapier 在他已经是 Discourse 成员的情况下,为他开放新组的访问权限。

您知道如何实现这一点吗?

1 个赞