Slack事件适配器:如何在我的Python脚本中从Slack Channel打印URL?

问题描述

我使用Python中的Slack Events API进行操作,并希望打印在我发布机器人的频道中的传入消息中检测到的URL(并将其保存到JSON文件)。这是我在ngrok的检查器上看到的输出

ok": true,"oldest": "0000000010.000000","messages": [{
            "type": "message","subtype": "bot_message","text": "","ts": "1593973316.000100","bot_id": "B016C8R3STD","attachments": [{
                "author_name": "Ariana Grande","fallback": "should\u2019ve stapled these to my eyelids when i had the chance. \nmiss n love u guys.\n*score* -1.64x | *Likes* 83,508 (-136,902) | *Comments* 4,969 (+1,921)\n_Posted on Sunday,July 5 at 8:19 PM CEST <https:\/\/www.instagram.com\/p\/CCRSzmNF8O3\/|(Instagram)>_\n_Received via Viral Alert_","text": "should\u2019ve stapled these to my eyelids when i had the chance. \nmiss n love u guys.\n*score* -1.64x | *Likes* 83,"id": 1,...

现在,我想在Python脚本中打印instagram-URL,例如:

    # Example save insta-shortcode from message

@slack_events_adapter.on("message")
def handle_message(event_data):
    message = event_data["event"]
    # If the incoming message contains "www.instagram.com/p/",then save string after "/p/" (or complete link) to JSON-file
    if message.get("subtype") == "bot_message" and "www.instagram.com/p/" in message.get('text'):
    print(string_after_/p/)
    +
    save_url_to_json_file (???)

实际上,它没有检测到insta字符串,我也不知道如何进入“附件”列表来获取它。也许有人编码建议?多谢!克里斯西(Chrissi)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)