我正在开发一个 Slackbot。导入 slackclient 后,我得到了ModuleNotFoundError: No module named 'slackclient'.
我尝试了所有选项,并遵循了此处帖子中显示的建议 - Python can't findinstalled module ('slackclient')。根据这些建议,我安装了 slack,但在导入 WebClient 时出现以下错误。
>>> from slack import WebClient
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'WebClient' from 'slack' (<path_to _venv>/.venv/lib/python3.7/site-packages/slack/__init__.py)
Run Code Online (Sandbox Code Playgroud)
我检查了 slack 版本,看起来还可以
slack 0.0.2
Run Code Online (Sandbox Code Playgroud)
有什么建议我可能做错了什么吗?
我试图理解一个异步函数,将其转换为用例的同步类型,
该函数正在使用 Node 的 https 模块向 Slack 发出 Post 请求,
我希望转换此代码以使用该axios库。
我无法理解发送到端点的帖子正文到底是什么。
功能代码如下——
function postToSlack(logTitle, logMessage, logType, context) {
var payloadStr = JSON.stringify({
'username': slackBotUsername,
'attachments': [
{
'title': logTitle,
'fallback': logMessage,
'text': logMessage,
'color': getLogTypeColour(logType)
}
],
'icon_emoji': slackBotIconEmoji,
});
var options = {
hostname: 'hooks.slack.com',
port: 443,
path: slackPostPath,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(payloadStr),
}
};
var postReq = https.request(options, function(res) {
var chunks = [];
res.setEncoding('utf8');
res.on('data', function(chunk) {
return chunks.push(chunk);
}); …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个模式,使用户能够输入日期以供进一步使用。该日期不能是过去或现在的日期(只能是未来的日期)。Slack表示可以在这里验证输入数据并在模态视图中显示错误,但我并不真正理解这种方法(我是一个自学者和新手)。
这是我的view对象view.open:
{
type: "modal",
callback_id: "tests",
title: {
type: "plain_text",
text: "Tests",
emoji: true
},
submit: {
type: "plain_text",
text: "Send",
emoji: true
},
close: {
type: "plain_text",
text: "Cancel",
emoji: true
},
blocks: [
{
type: "input",
block_id: "datepicker",
optional: false,
element: {
action_id: "calendar",
type: "datepicker",
initial_date: "2020-09-05",
placeholder: {
type: "plain_text",
text: "Select a date",
emoji: true
}
},
label: {
type: "plain_text",
text: "Label",
emoji: true
}
}
] …Run Code Online (Sandbox Code Playgroud)我正在使用网络钩子在 Slack 通道中发布模式交互消息,但该消息未显示在 Slack 通道中。
\nSlack 文档中有一些关于触发器 id 的信息,但非常令人困惑。
\n下面是我的 JSON 有效负载,其中我使用 Slack 中的预构建模板并使用 Web 挂钩将消息发送到 Slack 通道。
\nvar message={};\nvar attachments = [];\nvar attachment = {\n "type": "modal",\n "submit": {\n "type": "plain_text",\n "text": "Submit",\n "emoji": true\n },\n "close": {\n "type": "plain_text",\n "text": "Cancel",\n "emoji": true\n },\n "title": {\n "type": "plain_text",\n "text": "Your accommodation",\n "emoji": true\n },\n "blocks": [\n {\n "type": "section",\n "text": {\n "type": "plain_text",\n "text": "Please choose an option where you\'d like to stay …Run Code Online (Sandbox Code Playgroud)我们在 Slack 应用程序的 oauth 和权限部分配置了两个重定向 url(不同的域和有效的 https url)。当我们尝试 sso 时,它对于第一个重定向 url 工作正常,当对第二个重定向 url 执行 sso 时,我们得到 {"ok":false,"error":"bad_redirect_uri"}。请帮助我们解决问题
在 Slack 中,我使用斜杠命令设置了一个应用程序。当我使用本地ngrok服务器时,该应用程序运行良好。
但是,当我将应用程序服务器部署到 PCF 时,它返回 502 错误:
\n[CELL/0] [OUT] Downloading droplet...\n[CELL/SSHD/0] [OUT] Exit status 0\n[APP/PROC/WEB/0] [OUT] Exit status 143\n[CELL/0] [OUT] Cell e6cf018d-0bdd-41ca-8b70-bdc57f3080f1 destroying container for instance 28d594ba-c681-40dd-4514-99b6\n[PROXY/0] [OUT] Exit status 137\n[CELL/0] [OUT] Downloaded droplet (81.1M)\n[CELL/0] [OUT] Cell e6cf018d-0bdd-41ca-8b70-bdc57f3080f1 successfully destroyed container for instance 28d594ba-c681-40dd-4514-99b6\n[APP/PROC/WEB/0] [OUT] \xe2\x9a\xa1\xef\xb8\x8f Bolt app is running! (development server)\n[OUT] [APP ROUTE] - [2021-12-23T20:35:11.460507625Z] "POST /slack/events HTTP/1.1" 502 464 67 "-" "Slackbot 1.0 (+https://api.slack.com/robots)" "10.0.1.28:56002" "10.0.6.79:61006" x_forwarded_for:"3.91.15.163, 10.0.1.28" x_forwarded_proto:"https" vcap_request_id:"7fe6cea6-180a-4405-5e5e-6ba9d7b58a8f" response_time:0.003282 gorouter_time:0.000111 app_id:"f1ea0480-9c6c-42ac-a4b8-a5a4e8efe5f3" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 AWS 中创建一个 SNS 主题并订阅一个 lambda 函数,该函数将向 Slack 应用程序/用户发送通知。
我确实读过这篇文章 - https://aws.amazon.com/premiumsupport/knowledge-center/sns-lambda-webhooks-chime-slack-teams/
描述了如何使用此 lambda 代码执行此操作:
#!/usr/bin/python3.6
import urllib3
import json
http = urllib3.PoolManager()
def lambda_handler(event, context):
url = "https://hooks.slack.com/services/xxxxxxx"
msg = {
"channel": "#CHANNEL_NAME",
"username": "WEBHOOK_USERNAME",
"text": event['Records'][0]['Sns']['Message'],
"icon_emoji": ""
}
encoded_msg = json.dumps(msg).encode('utf-8')
resp = http.request('POST',url, body=encoded_msg)
print({
"message": event['Records'][0]['Sns']['Message'],
"status_code": resp.status,
"response": resp.data
})
Run Code Online (Sandbox Code Playgroud)
但问题是,在该实现中我必须为每个用户创建一个 lambda 函数。
我想要将多个 Slack 应用程序/用户订阅一个 SNS 主题。有没有一种方法可以做到这一点,而无需为每个函数创建 lambda 函数?
我正在尝试使用 Ruby 为我的团队编写一个简单的 Slack 聊天机器人。这有点粗糙,因为 Slack 没有对 Ruby 的官方支持。尽管如此,我已经能够使用我编写的代码打开 websocket 并监听 Slack 事件:
# frozen_string_literal: true
require "async"
require "async/io/stream"
require "async/http/endpoint"
require "async/websocket/client"
require "excon"
require "json"
module Slack
class Client
Error = Class.new(StandardError)
AquisitionError = Class.new(Error)
ConnectionError = Class.new(Error)
CONNECTION_AQUISITION_ENDPOINT = "https://slack.com/api/apps.connections.open"
def initialize
@token = "my-app-token"
end
def connect
connection_info = Excon.post(CONNECTION_AQUISITION_ENDPOINT, headers: {
"Content-type": "application/x-www-form-urlencoded",
Authorization: "Bearer #{@token}",
})
result = JSON.parse(connection_info.body)
raise(AquisitionError) unless result["ok"] # better error later
websocket = Async::HTTP::Endpoint.parse(result["url"])
Async do |_task|
Async::WebSocket::Client.connect(websocket) …Run Code Online (Sandbox Code Playgroud) 我整合slack与jenkins使用slash命令和想知道slash的命令有variables
我想做的是这样的事情;
/this_word_should_be_in_the_url word
和能够使用word的URL斜线命令将调用.
在他们的页面上他们有类似的东西 /weather 94070
我是否可以访问94070并以某种方式设置作为queryURL 的参数.
这可能吗?找不到任何这方面的文件.
谢谢.
我使用microsoft bot框架创建了一个slackbot.有没有办法获取邮件发件人的姓名?
例如,我有以下代码.
`
bot.dialog('/raiseTask',
function (session, args, next) {
session.send('Hi');
}
);
Run Code Online (Sandbox Code Playgroud)
`
我知道信息存储在会话内部,关于文本的类型和发送者在松散到机器人时发送的实际消息.在查看文档并仔细阅读之后,我没有成功找到有关查找发件人姓名的任何相关信息.
更确切地说,我想要实现的功能是:
赛义夫:嗨@slackbot slackbot:嗨赛义夫
大卫:嗨@slackbot slackbot:嗨大卫
谢谢!
slack ×10
slack-api ×8
node.js ×2
aws-lambda ×1
botframework ×1
javascript ×1
modal-dialog ×1
pcf ×1
python ×1
python-3.x ×1
ruby ×1
websocket ×1