开发者社区> 问答> 正文

使用Microsoft Bot框架创建python主动消息传递 问问题

使用带有Microsoft bot框架的Python创建推式通知/主动消息传递bot的步骤是什么?由于还没有官方文档,所以我真的不知道从哪里开始。

我已导入以下内容:

from botbuilder.schema import Activity, ActivityTypes, ConversationReference 如何使用它,这是一个非常简单的示例?

展开
收起
祖安文状元 2020-02-23 16:09:43 844 0
1 条回答
写回答
取消 提交回答
  • 我为您制作了一个基于状态管理示例的示例演示。请按照以下步骤操作:1.在下面添加代码app.py:

    @APP.route("/api/notify", methods=["POST"])
    def notify():
        if request.headers["Content-Type"] == "application/json":
            body = request.json
        else:
            return Response(status=415)
    
        activity = Activity().deserialize(body)
    
        auth_header = (
            request.headers["Authorization"] if "Authorization" in request.headers else ""
        )
    
        async def aux_func(turn_context):
            await BOT.on_turn(turn_context)
    
        try:
            task = LOOP.create_task(
                ADAPTER.process_activity(activity, auth_header, aux_func)
            )
            LOOP.run_until_complete(task)
            return Response(status=201)
        except Exception as exception:
            raise exception
    
    
    1. on_message_activity在state_management_bot.py下面的代码中修改功能
    async def on_message_activity(self, turn_context: TurnContext):
        # Get the state properties from the turn context.
    
        if(turn_context.activity.channel_id != 'notify'):
           await turn_context.send_activity("You asid:" + turn_context.activity.text);
        else:
           await turn_context.send_activity("You get a notify : "+ turn_context.activity.text);
    
    2020-02-23 16:10:04
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载