Mattermost API 使用 powershell 创建直接消息通道
Mattermost API create a direct message channel with powershell
我找不到足够的文档或工作示例。
从官网看好像是possible,我试过这个:
$Payload = { text:Hello; username:bot; channel:user}
Invoke-RestMethod -Uri https://mymattermost.com/hooks/%Bearer token% -Method Post
-ContentType 'application/json' -Body (ConvertTo-Json $Payload
但总是得到同样的错误:
Invoke-RestMethod : {"id":"web.incoming_webhook.text.app_error","message":"No text
specified","detailed_error":"","request_id":"aaaaaaaaaaaaaaa","status_code":400}
At line:1 char:1
嗯,你所要做的就是在 channels
下为用户名添加 @
就可以了,就像这样:
> $Payload = @{ text="Hello"; username="bot"; channel="@user"}
> Invoke-RestMethod -Uri https://mymattermost.com/hooks/124twgvrq4tgw54e4 -Method Post
-ContentType 'application/json' -Body (ConvertTo-Json $Payload) -UseBasicParsing
这样就可以了。
注意:无论谁创建了 webhook,都将是分配给直接频道的用户
我找不到足够的文档或工作示例。
从官网看好像是possible,我试过这个:
$Payload = { text:Hello; username:bot; channel:user}
Invoke-RestMethod -Uri https://mymattermost.com/hooks/%Bearer token% -Method Post
-ContentType 'application/json' -Body (ConvertTo-Json $Payload
但总是得到同样的错误:
Invoke-RestMethod : {"id":"web.incoming_webhook.text.app_error","message":"No text
specified","detailed_error":"","request_id":"aaaaaaaaaaaaaaa","status_code":400}
At line:1 char:1
嗯,你所要做的就是在 channels
下为用户名添加 @
就可以了,就像这样:
> $Payload = @{ text="Hello"; username="bot"; channel="@user"}
> Invoke-RestMethod -Uri https://mymattermost.com/hooks/124twgvrq4tgw54e4 -Method Post
-ContentType 'application/json' -Body (ConvertTo-Json $Payload) -UseBasicParsing
这样就可以了。 注意:无论谁创建了 webhook,都将是分配给直接频道的用户