Exemple #1
0
def restart(session, topic_id, other_user_id):
    """ Restart a stopped conversation.
    """
    raise UnauthorizedException() # Disable for now.

    if session == None or topic_id == None or other_user_id == None:
        raise InvalidParametersException()

    sessionHandler.validate(session)
    user = sessionHandler.get_user(session)

    try:
        topic = Topic.objects.get(id=topic_id)
    except Topic.DoesNotExist:
        raise NoSuchTopicException()

    try:
        other_user = User.objects.get(id=other_user_id)
    except User.DoesNotExist:
        raise NoSuchUserException()

    conversation = conversationHandler.get(user.id, other_user.id, topic.id)

    conversationHandler.send_to_both_parties(
        conversation, settings.SMS_TEXT_CONVERSATION_RESTARTING)

    conversation.stopped = False
    conversation.save()
Exemple #2
0
def handle_special_message(sender, recipient, topic, message_text):
    """ Handle a message that needs to be dealt with specially.

        The parameters are as follows:

            'sender'

                The User who sent this SMS message.

            'recipient'

                The other User in this conversation.

            'topic'

                The Topic this conversation is about.

            'message_text'

                The text of the message.

        When receiving a message, this function is called to see if it needs to
        be handled specially.  Certain commands can be embedded within the
        message text, triggering specific actions within the MessageMe core.

        If the given message text contains a special message, that message is
        processed and we return True.  Otherwise, we return False.
    """
    if message_text.lower() == "stop":
        # Stop the associated conversation.
        conversation = conversationHandler.get(sender.id,
                                               recipient.id,
                                               topic.id)
        conversation.stopped = True
        conversation.save()
        conversationHandler.send_to_both_parties(
            conversation, settings.SMS_TEXT_CONVERSATION_ENDED)
        return True
    else:
        return False