使用 discourse-chat-integration 插件设置 Microsoft Teams 通知

本指南介绍如何设置 discourse-chat-integration 中包含的 Microsoft Teams 提供程序。

设置 Microsoft Teams

在 Microsoft Teams 中:

  1. 从左侧的垂直导航栏中,单击省略号按钮()并从菜单中选择 工作流Workflows)。

  2. 在“工作流”(Workflows)页面的右上角,单击 + 从头开始构建+ Build from scratch)按钮。

  3. 在自定义工作流模态框中,搜索 webhook 并选择 当收到 Teams webhook 请求时When a Teams webhook request is received)触发器。

  4. 谁可以触发流Who can trigger the flow)字段中,选择 任何人Anyone)。[1]

  5. 单击 + 新建步骤+ New step)。

  6. 接下来,搜索 card 并选择 在聊天或频道中发布卡片Post card in a chat or channel)操作。

  7. 按照以下方式填写字段:

  • 以…身份发布Post as:):选择消息应来自谁;您可以将其保留为默认值,或选择 用户User)使消息看起来像是来自您。

  • 在…中发布Post in:):选择 频道Channel),这将显示更多字段:

    • 团队Team:):选择所需的团队。
    • 频道Channel:):选择所需的频道。
    • 自适应卡片Adaptive Card:):单击输入框,这将打开一个弹出窗口(在下一步中描述)。

  1. 单击 自适应卡片Adaptive Card)字段以打开一个弹出窗口 [2] 以插入动态内容或表达式。切换到 表达式Expression)选项卡,并在表达式字段中输入 triggerBody()

  2. 单击 保存Save)。

  3. 您现在应该在列表中看到一个名为 manual → Post card in a chat or channel 的工作流。单击此工作流上的垂直省略号按钮,然后从下拉菜单中选择 详细信息Details)。

  4. 在此页面上,单击 复制 webhook 链接Copy webhook link)以获取下一步所需的链接。在此期间,您可以选择编辑工作流名称,以反映其对团队中其他人的目的。

设置 Discourse

现在,回到 Discourse:

  1. 在您的 Discourse 管理区域中,启用 Chat integration enabled 设置以开启“聊天集成”插件,并启用 Chat integration Teams enabled 设置以支持 Microsoft Teams。

  2. 在侧边栏中,找到 插件Plugins)部分并单击 聊天集成Chat Integrations),然后单击 + 创建频道+ Create Channel)。

  3. 编辑频道Edit Channel)模态框中,按如下方式填写字段:

  • 名称Name:):输入一个名称,使其清楚地表明您正在连接到哪个 Microsoft Teams 频道;它不需要完全匹配。
  • Webhook URL:粘贴您在上面 Teams 设置部分的第 11 步中复制的 webhook URL。
  1. 单击 保存频道Save Channel)。

测试集成

现在是时候确保一切都按预期工作了。

  1. 在 Discourse 中,单击新创建的频道上的 测试Test)。

  2. 按 ID、标题或 URL 搜索主题;选择所需的主题;然后单击 发送测试消息Send Test Message)。

  3. 在 Microsoft Teams 中,一条包含主题信息的新消息将发布到频道中:

可选:为您的频道设置规则

确认一切正常后,您可以返回 Discourse 并为您的频道设置其他规则来定制消息。

调试

如果您没有在 Microsoft Teams 中看到预期的消息,请转到 工作流详细信息Workflow Details)页面(参见上面 Teams 设置部分的第 10 步),并检查 运行历史记录Run history)部分。这应该会显示每次消息运行的日志。

单击失败的运行,这将带您进入 Power Automate 区域,您可以在页面顶部看到错误消息。(在下面的截图中,运行成功了,但箭头指示了失败的运行中错误出现的位置。)

这应该会详细说明问题,然后您可以修复它或在此处与我们分享,以便我们提供帮助。


    1. Discourse 目前不支持向 Teams 进行身份验证的 webhook,因此只有“任何人”选项才有效。
    ↩︎
  1. 如果弹出窗口未出现,请暂时在“自适应卡片”字段中输入任何内容,保存工作流,再次打开进行编辑,此时弹出窗口应该会出现。 ↩︎

12 个赞

Just tried it out and it seemed to work at first, but only the first time I clicked on the test button.
Rules are set up as follows:

  • Type: normal
  • Filter: All topics(?) and replies (translating from German here)
  • Category: Sandbox

When I wrote a reply to the test topic in my Sandbox category I got a warning sign when I went to my chat integrations, but when clicking on the warning triangle it says unknown error... with the error message bein null.

When I try to send another test notification it gives me another error 500 internal server error

Any hints on where to start trouble shooting this are welcome. If this should be posted elsewhere (e.g. under the chat integration plugin page), or made a separate topic, feel free to move it accordingly or let me know.

3 个赞

Hi @SHilser - please can you check /logs on your site, and see if there is anything relevant there?

2 个赞

There’s two things that seem relevant.

  • Socket Error
  • Internal Server Error

I copied the logs below (I replaced my domain name with mydomain.tld)

Socket Errror

Message (4 copies reported)

SocketError (Failed to open TCP connection to outlook.office.com:443 (getaddrinfo: Temporary failure in name resolution))
app/controllers/application_controller.rb:340:in `block in with_resolved_locale'
app/controllers/application_controller.rb:340:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:68:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:336:in `call'
config/initializers/100-quiet_logger.rb:19:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:22:in `call'
lib/middleware/request_tracker.rb:176:in `call'

Backtrace

/usr/local/lib/ruby/2.6.0/net/http.rb:949:in `rescue in block in connect'
/usr/local/lib/ruby/2.6.0/net/http.rb:946:in `block in connect'
/usr/local/lib/ruby/2.6.0/timeout.rb:93:in `block in timeout'
/usr/local/lib/ruby/2.6.0/timeout.rb:103:in `timeout'
/usr/local/lib/ruby/2.6.0/net/http.rb:945:in `connect'
/usr/local/lib/ruby/2.6.0/net/http.rb:930:in `do_start'
/usr/local/lib/ruby/2.6.0/net/http.rb:919:in `start'
/usr/local/lib/ruby/2.6.0/net/http.rb:1470:in `request'
rack-mini-profiler (2.0.4) lib/patches/net_patches.rb:19:in `block in request_with_mini_profiler'
rack-mini-profiler (2.0.4) lib/mini_profiler/profiling_methods.rb:33:in `step'

Env

HTTP HOSTS: mysite.tld

Internal Server Error

Message (4 copies reported)

Error: Internal Server Error
Url: https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js
Line: 1
Column: 267890
Window Location: https://mysite.tld/admin/plugins/chat/teams

Backtrace

o/t</<@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:267890
o/t<@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:267993
o@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:268074
trigger@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:545343
A</e._onError/<@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:550189
f</t.invoke@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:490190
f</t.flush@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:489198
p</t.flush@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:491205
t</t._end@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:496596Here
t</t.end@https://mysite.tld/assets/ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:1:493157

Env

HTTP HOSTS: mysite.tld

Thanks for the help :slight_smile:

2 个赞

That suggests that your server is having trouble with DNS resolution. Are you using a standard docker-based installation? Or is this in development?

3 个赞

Just set it up about a week ago on a separate DigitalOcean droplet (one-click installation, now I’m on Version: 2.6.0.beta1 (310952fd6a). I use a subdomain and have the DNS records also on DigitalOcean. I have an A-Record, pointing to the IP, MX-Record pointing to the sub-domain name for reply by email as per these instruction). Only thing there is that I don’t have a DMARC Record published.

That’s all I can think of that I did in relation to DNS stuff. However, so far everything worked as expected. The site is set up, I can reach it via the sub-domain name, log-in, create topics (even via email), etc.

I’m just startled the first message made it through, but subsequent ones didn’t :man_shrugging:

2 个赞

When I say DNS resolution, I mean your server is having trouble contacting outlook.office.com. The setup of your forum’s DNS records shouldn’t affect that.

Can you try connecting to your server via SSH and running

host outlook.office.com

You should get something like

outlook.office.com is an alias for substrate.office.com.
substrate.office.com is an alias for substrate.ms-acdc.office.com.
substrate.ms-acdc.office.com is an alias for afd-k.office.com.
afd-k.office.com is an alias for outlook-office-com.k-0002.k-msedge.net.
outlook-office-com.k-0002.k-msedge.net is an alias for k-0002.k-msedge.net.
k-0002.k-msedge.net has address 13.107.18.11
k-0002.k-msedge.net has IPv6 address 2620:1ec:c::11
3 个赞

When I enter

host -d outlook.office.com

I get the following:

Trying "outlook.office.com"
Host outlook.office.com not found: 2(SERVFAIL)
Received 36 bytes from 127.0.0.53#53 in 43 ms

When adding port :443 I get another error

Trying "outlook.office.com:443"
Host outlook.office.com:443 not found: 3(NXDOMAIN)
Received 40 bytes from 127.0.0.53#53 in 3 ms
Received 40 bytes from 127.0.0.53#53 in 3 ms

For other domains like google.com or the domain of my discourse instance in question (h-da.transformative-praxis.cc), or other sites I get the expected output similar to what you describe.

I did some search for the first error, but I’m still not sure about its source. I’ve read the following, but wasn’t able to judge, if this is actually relevant to my problem:

1 个赞

I kept retrying it and this time I got the results you described when typing

host outlook.office.com

So everything seemed fine at this point. I’ve repeated that many times in a row to make sure (like around 15 times with an interval of around 10 seconds) and at some point I got the same servfail error as before. But mostly it worked.

The opposite is the case when I try to send a test message. It maybe works one out of ten times. The other times I get the same errors as before. And when I post a regular message that fits to the rule I’ve set for the channel, I don’t get a notification, nor an error message in the logs.
It just seems so random to me that I can’t find out what causes it.

I kept suspecting my setup with two droplets for each subdomain and two respective A-Records, plus one set of NS-records for my main domain pointing to ns1.digitalocean.com. So I tried out dnsstuff for my site getting a Fail for the SOA record check and whatsmydns.net for my NS records, but I still couldn’t figure out any possible connections to my problem.

At this point I’m totally confused who’s causing the error, me having made some wrong DNS settings (which shouldn’t affect it according to @david), server settings/issues, or is it just MS-Teams (outlook.office.com) acting up, or blocking me in some way?

Any hints for what I could check/do to find the error are appreciated, including where else to go and ask, if you think this is beyond what you can do to help me here.

Thanks a lot for all the help so far.

1 个赞

Hi, thanks for this. I keep failing at step Discourse 5: The dialogue box says my incoming Webhooks URL is invalid?

Any help appreciated!

Dan

1 个赞

Would you mind sharing what your webhook URL looks like? Either via PM to me or, if you can invalidate it first, here in the topic?

1 个赞

Thanks @Dan_Turner, I just relaxed our validation a little which should help the situation. Please give it a try and let me know if it works better for you

https://github.com/discourse/discourse-chat-integration/commit/00ec1f486a3fd1dc523cdf242cfb1c78baaa407e

2 个赞

Thanks! Will give it a try.

Dan

1 个赞

Sorry to be thick but do I need to update Discourse or edit the file directly as detailed in the fix?
Thanks, Dan

1 个赞

You need to update the plugin. Visit /admin/upgrade, and press the update button next to “Discourse-chat-integration”

2 个赞

Hey - so sorry for being incompetent but - how do I actually try this as I’m on a hosted discourse instance? Thanks. Dan

1 个赞

You will need to ask your hosting provider to update the plugin for you. At discourse.org this change has already gone out to all our customers, so I guess you must be hosted elsewhere?

1 个赞

yeah, discourse hosting for me. which version is it in please and I will ask them to update?

1 个赞

We don’t have version numbers for plugins, but you can share this commit link with them: https://github.com/discourse/discourse-chat-integration/commit/00ec1f486a3fd1dc523cdf242cfb1c78baaa407e

2 个赞

感谢这个非常有用的插件。
一个很大的改进是:在消息中添加群组提及,以便在 Teams 端生成通知。
看起来 webhook API (过去)没有实现此功能,但有人说它最近已实现。
您认为可以轻松实现吗?