Пример #1
0
def test_handle_verification_affirmative_message(sleep, database):
    client = mock.create_autospec(nexmo.Client, instance=True)

    client.application_id = "appid"
    client.send_message.return_value = {"messages": [{"error-text": ""}]}

    injector.set("nexmo.client", client)

    hotline_virtual_number = "1234567890"
    injector.set("secrets.virtual_number", hotline_virtual_number)

    event = helpers.create_event()

    responses = ("ok", "yes", "okay")
    for response in responses:
        member = helpers.add_unverfied_members(event)
        verification.maybe_handle_verification(member.number, response)

        member = db.get_member_by_number(member.number)
        assert member.verified

        expected_msg = "Thank you, your number is confirmed."
        client.send_message.assert_called_with({
            "from": event.primary_number,
            "to": member.number,
            "text": expected_msg
        })
Пример #2
0
def inbound_sms():
    message = flask.request.get_json()

    # TODO NZ: log member name here instead of phone number
    # from_number_last_four = message['msisdn'][-4:]
    logger.info(f"Handling a message to {message['to']}")

    user_number = lowlevel.normalize_e164_number(message["msisdn"])
    relay_number = lowlevel.normalize_e164_number(message["to"])
    message_text = message["text"]

    # Maybe handle verification, if this is a response to a verification message.
    verification.maybe_handle_verification(user_number, message_text)

    return "", 204
Пример #3
0
def test_handle_verification_negative_message(sleep, database):
    client = mock.create_autospec(nexmo.Client, instance=True)

    client.application_id = "appid"
    client.send_message.return_value = {"messages": [{"error-text": ""}]}

    injector.set("nexmo.client", client)

    hotline_virtual_number = "1234567890"
    injector.set("secrets.virtual_number", hotline_virtual_number)

    event = helpers.create_event()

    responses = ("nyet", "nay", "no way")
    for response in responses:
        member = helpers.add_unverfied_members(event)
        verification.maybe_handle_verification(member.number, response)

        member = db.get_member_by_number(member.number)
        assert not member.verified

        client.send_message.assert_not_called()
Пример #4
0
def inbound_sms():
    message = flask.request.get_json()
    user_number = lowlevel.normalize_e164_number(message["msisdn"])
    relay_number = lowlevel.normalize_e164_number(message["to"])
    message_text = message["text"]

    # Maybe handle verification, if this is a response to a verification message.
    if verification.maybe_handle_verification(user_number, message_text):
        return "", 204

    # It's not verification, so hand it off to SMS chat
    try:
        smschat.handle_message(user_number, relay_number, message_text)
    except smschat.SmsChatError as err:
        smschat.handle_sms_chat_error(err, user_number, relay_number)

    return "", 204