예제 #1
0
파일: __init__.py 프로젝트: 2Fake/core
async def handle_webhook(hass, webhook_id, request):
    """Handle incoming webhook from Twilio for inbound messages and calls."""
    data = dict(await request.post())
    data["webhook_id"] = webhook_id
    hass.bus.async_fire(RECEIVED_DATA, dict(data))

    return TwiML().to_xml()
예제 #2
0
 def post(self, request):  # pylint: disable=no-self-use
     """Handle Twilio data post."""
     from twilio.twiml import TwiML
     hass = request.app['hass']
     data = yield from request.post()
     hass.bus.async_fire(RECEIVED_DATA, dict(data))
     return TwiML().to_xml()
예제 #3
0
def customer_response(request):
    body = request.POST.get("Body", "")
    number = request.POST.get("From", "")
    print("Body", body)
    print("Sender", number)

    conversation_checkpoint = request.session.get("checkpoint")
    sms_feedback = SMSFeedback.objects.get(phone_number=number)
    params = urllib.parse.urlencode({})

    docs = {"documents": [{"language": "en", "id": "1", "text": body}]}
    try:
        conn = http.client.HTTPSConnection(
            'westus.api.cognitive.microsoft.com')
        conn.request("POST", "/text/analytics/v2.0/sentiment?%s" % params,
                     json.dumps(docs), headers)
        response = conn.getresponse()
        data = response.read()

        logger.info("Sentiment API Response")
        logger.info("{Response}".format(Response=data))

        analytics_response = json.loads(data.decode('utf-8'))
        sentiment = analytics_response["documents"][0]["score"]
        conn.close()
    except Exception as e:
        logger.error("Sentiment API Error")
        logger.error("[Errno {0}] {1}".format(e.errno, e.strerror))

    response = MessagingResponse()

    if conversation_checkpoint == "end":
        response = TwiML()
        request.session.flush()
    elif conversation_checkpoint == 'follow_up':
        response.message("Thank you for your follow up!")
        sms_feedback.follow_up = body
        sms_feedback.save()
        request.session["checkpoint"] = "end"
    else:
        if (sentiment > 0.5):
            response.message(sms_feedback.positive_reply)
        else:
            response.message(sms_feedback.negative_reply)
        request.session["checkpoint"] = "follow_up"

    return HttpResponse(str(response), content_type='text/xml')
예제 #4
0
 def test_append_fail(self):
     t = TwiML()
     t.append('foobar')
예제 #5
0
 def test_append_fail(self):
     t = TwiML()
     t.append(12345)
예제 #6
0
 def test_append_fail(self):
     t = TwiML()
     t.append(12345)
예제 #7
0
 def test_append_fail(self):
     t = TwiML()
     t.append('foobar')
예제 #8
0
 def __init__(self, *args, **kwargs):
     TwiML.__init__(self)
     FlaskResponse.__init__(self, *args, **kwargs)