首页 > 解决方案 > How to keep listening for a request at the same time process another request in python

问题描述

So, it'a little complicated.

What I am trying to do:

  1. Hosting an app on heroku and listening for webhooks sent by a messaging app (in JSON format) and saving them to a Database(SQLite3).
  2. Use that Database to generate ticket on zoho desk.
  3. If the ticket status is open I'll update the ticket with the new message otherwise I create a new ticket.
  4. Overall it includes two processes: Listening for webhooks and creating a ticket

My problem/worries:

  1. I am able to listen for the webhooks but the problem I am facing is that when I am creating a ticket how can the same script listen for webhooks or vice and versa.
  2. I have no idea how I can make these things so that while updating/creating a ticket I should be able to receive webhooks.

Sample code to listen to webhooks(JSON files sent via POST method).

from flask import Flask, request, Response

app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def respond():
    print(request.json);
    return Response(status=200)

标签: jsonapiflaskherokuticket-system

解决方案


你的过程不是很清楚。根据你的说法

  1. 您收到一条消息(通过 webhook)

  2. 然后你去生成一张票

  3. 如果工单状态为打开,您将使用步骤 1 中的消息更新工单

    评论-如果您在第 2 步中生成了工单,那么为什么此工单状态不会打开?新票应该是开放状态,对吧?

  4. 如果工单状态为未打开,您将创建一个新工单

    评论-但您说您在第 2 步生成票证?

也许我误解了你输入的内容,但你能更清楚地说明你的过程吗?


推荐阅读