예제 #1
0
def respond(sender_id, message_text, attachment_type, attachment_url, postback,
            quick_reply, context):
    from bot.lib.project import update_project
    """Takes in ``sender_id``, ``message_text``= #keywords,``context``= project id
    updates project and sends a reponse.

    :param str sender_id: The unique id created by facebook and the current facebook's sender's ID
    :param str message_text: Any text written by the send in the chat interface
    :param dict context: attributes sent between conversations
    :param str attachment_type: dentifies attachment type i.e photo (optional, defaults to None)
    :param str attachment_url: The location of the attachment (optional, defaults to None)
    :param str postback: a reponse sent from the user clicking a button (optional, defaults to None)
    :param str quick_reply: an automatic reply (optional, defaults to None)

    :returns: ``reponse``a dict with the next message to move the conversation
    ``new_context`` empty dict, and ``coverstation`` dict containing
    the next stage and task for the the bot
    """

    tags = [i.strip() for i in message_text.split('#')]
    update_project(sender_id=sender_id,
                   project_id=context['project_id'],
                   tags=tags)
    new_context = dict()

    response = dict(
        message_text=
        "You're all done! Head back to the menu if you want to do anything else"
    )
    conversation = dict(name='menu', stage='menu')
    return response, new_context, conversation
예제 #2
0
def respond(sender_id, message_text, attachment_type, attachment_url, postback,
            quick_reply, context):
    from bot.lib.project import update_project
    from .utilities import send_date_picker
    """Takes in ``sender_id``, ``postback``= supply id,
     ``context`` = project id and updates project and sends a reponse.

    :param str sender_id: The unique id created by facebook and the current facebook's sender's ID
    :param str postback: a reponse sent from the user clicking a button (optional, defaults to None)
    :param dict context: attributes sent between conversation in the case project_id
    :param str message_text: Any text written in the chat interface (optional, defaults to None)
    :param str attachment_type: dentifies attachment type i.e photo (optional, defaults to None)
    :param str attachment_url: The location of the attachment (optional, defaults to None)
    :param str quick_reply: an automatic reply (optional, defaults to None)

    :returns: ``reponse``a dict with the next message to move the conversation
    ``new_context`` same context as before, and ``coverstation`` dict containing
    the next stage and task for the the bot
    """

    update_project(sender_id=sender_id,
                   project_id=context["project_id"],
                   material_id=postback)
    conversation = dict(name='create_project', stage='add_due_date')
    response = dict(
        message_text=
        "Awesome! That's all I need. When do you want to finish this project by"
    )
    new_context = context

    response = send_date_picker(sender_id=sender_id)

    return response, new_context, conversation
예제 #3
0
def respond(sender_id, message_text, attachment_type, attachment_url, postback,
            quick_reply, context):
    """Takes in ``sender_id``, ``attachment_type``= photo,``attachment_url``= url,
     ``context`` = project id and updates project and sends a reponse.

    :param str sender_id: The unique id created by facebook and the current facebook's sender's ID
    :param str attachment_type: dentifies attachment type i.e photo
    :param str attachment_url: The location of the attachment
    :param dict context: attributes sent between conversation in the case project_id
    :param str message_text: Any text written in the chat interface (optional, defaults to None)
    :param str postback: a reponse sent from the user clicking a button (optional, defaults to None)
    :param str quick_reply: an automatic reply (optional, defaults to None)

    :returns: ``reponse``a dict with the next message to move the conversation
    ``new_context`` same context as before, and ``coverstation`` dict containing
    the next stage and task for the the bot
    """
    from bot.lib.material import create_material
    from bot.lib.project import update_project
    from .utilities import send_date_picker

    material = create_material(sender_id=sender_id,
                               url=attachment_url,
                               file_type=attachment_type)
    update_project(sender_id=sender_id,
                   project_id=context["project_id"],
                   material_id=str(material.id))
    new_context = context
    conversation = dict(name='create_project', stage='add_due_date')
    response = send_date_picker(sender_id=sender_id)
    return response, new_context, conversation
예제 #4
0
    def setUp(self):
        from bot.lib.maker import create_maker
        from bot.lib.project import create_project, update_project
        from bot.lib.material import create_material
        from bot.lib.pattern import create_pattern

        self.sender_id = '1'
        self.pattern_url = 'http://via.placeholder.com/350x150'
        self.pattern_type = 'image'
        self.material_url = 'http://via.placeholder.com/350x150'
        self.material_type = 'image'
        self.project_name = 'test_project'
        self.due_date = '2018-01-01'
        self.tags = ['1', '2', '3']
        self.update_url = 'http://via.placeholder.com/350x150'
        self.update_type = 'image'
        create_maker(sender_id=self.sender_id)
        project, created = create_project(sender_id=self.sender_id,
                                          name=self.project_name)
        self.project = project
        self.material = create_material(sender_id=self.sender_id,
                                        url=self.material_url,
                                        file_type=self.material_type)
        self.pattern = create_pattern(sender_id=self.sender_id,
                                      url=self.pattern_url,
                                      file_type=self.pattern_type)

        update_project(sender_id=self.sender_id,
                       project_id=str(self.project.id),
                       date_string=self.due_date,
                       material_id=str(self.material.id),
                       pattern_id=str(self.pattern.id),
                       tags=self.tags)
예제 #5
0
    def setUp(self):
        from bot.lib.maker import create_maker
        from bot.lib.pattern import create_pattern
        from bot.lib.material import create_material
        from bot.lib.project import create_project, update_project

        self.sender_id = '108886223055545'
        create_maker(sender_id=self.sender_id)
        project, created = create_project(sender_id=self.sender_id,
                                          name='Test_project')
        self.pattern = create_pattern(sender_id=self.sender_id,
                                      url='http://via.placeholder.com/350x150',
                                      file_type='image')
        self.material = create_material(
            sender_id=self.sender_id,
            url='http://via.placeholder.com/350x150',
            file_type='image')

        update_project(sender_id=self.sender_id,
                       project_id=str(project.id),
                       material_id=str(self.material.id),
                       pattern_id=str(self.pattern.id),
                       date_string='2300-10-30')
        self.project = project
        project_2, created = create_project(sender_id=self.sender_id,
                                            name='Test_project_2')
예제 #6
0
    def test_add_tags(self):
        from bot.lib.project import update_project
        from bot.models import ProjectTag

        update_project(sender_id=self.sender_id,
                       project_id=str(self.project.id),
                       tags=self.tags)
        self.assertEqual(
            ProjectTag.objects.filter(project=self.project).count(), 3)
예제 #7
0
 def test_add_pattern(self):
     from bot.lib.project import update_project
     from bot.models import ProjectPattern
     update_project(sender_id=self.sender_id,
                    project_id=str(self.project.id),
                    pattern_id=str(self.pattern.id))
     self.assertEqual(
         ProjectPattern.objects.filter(project=self.project).filter(
             pattern=self.pattern).count(), 1)
예제 #8
0
 def test_add_material(self):
     from bot.lib.project import update_project
     from bot.models import ProjectMaterial
     update_project(sender_id=self.sender_id,
                    project_id=str(self.project.id),
                    material_id=str(self.material.id))
     self.assertEqual(
         ProjectMaterial.objects.filter(project=self.project).filter(
             material=self.material).count(), 1)
예제 #9
0
    def test_add_due_date(self):
        from bot.lib.project import update_project
        from bot.models import ProjectDueDate, Project

        update_project(sender_id=self.sender_id,
                       project_id=str(self.project.id),
                       date_string=self.due_date)
        self.assertEqual(
            ProjectDueDate.objects.filter(project=self.project).count(), 1)
        self.assertTrue(Project.objects.get(id=str(self.project.id)).complete)
예제 #10
0
def respond(sender_id, message_text, attachment_type, attachment_url, postback,
            quick_reply, context):
    from bot.lib.project import update_project
    """Takes in ``sender_id``, ``message_text``= due date,``context``= project id
    and sends a reponse.

    :param str sender_id: The unique id created by facebook and the current facebook's sender's ID
    :param str message_text: Any text written by the send in the chat interface
    :param dict context: attributes sent between conversation in the case project_id
    :param str attachment_type: dentifies attachment type i.e photo (optional, defaults to None)
    :param str attachment_url: The location of the attachment (optional, defaults to None)
    :param str postback: a reponse sent from the user clicking a button (optional, defaults to None)
    :param str quick_reply: an automatic reply (optional, defaults to None)

    :returns: ``reponse``a dict with the next message to move the conversation
    ``new_context`` same context as before, and ``coverstation`` dict containing
    the next stage and task for the the bot
    """

    project = update_project(sender_id=sender_id,
                             project_id=context['project_id'],
                             date_string=message_text)
    new_context = context

    response = dict(
        message_text=
        "Great. Do you want to add tags? or ... head back to the menu if you are done."
    )
    conversation = dict(name='create_project', stage='add_tags')
    return response, new_context, conversation
예제 #11
0
    def test_update_project_with_projects(self):
        from bot.tasks import route_message
        from bot.lib.conversation import get_conversation_stage_id
        from bot.models import Maker
        from bot.lib.maker import create_maker
        from bot.lib.project import create_project, update_project
        from bot.lib.material import create_material
        from bot.lib.pattern import create_pattern

        self.sender_id = '1'
        self.pattern_url = 'http://via.placeholder.com/350x150'
        self.pattern_type = 'image'
        self.material_url = 'http://via.placeholder.com/350x150'
        self.material_type = 'image'
        self.project_name = 'test_project'
        self.due_date = '2017-01-01'
        self.tags = ['1', '2', '3']
        self.update_url = 'http://via.placeholder.com/350x150'
        self.update_type = 'image'
        create_maker(sender_id=self.sender_id)
        project, created = create_project(sender_id=self.sender_id,
                                          name=self.project_name)
        self.project = project
        self.material = create_material(sender_id=self.sender_id,
                                        url=self.material_url,
                                        file_type=self.material_type)
        self.pattern = create_pattern(sender_id=self.sender_id,
                                      url=self.pattern_url,
                                      file_type=self.pattern_type)

        update_project(sender_id=self.sender_id,
                       project_id=str(self.project.id),
                       date_string=self.due_date,
                       material_id=str(self.material.id),
                       pattern_id=str(self.pattern.id),
                       tags=self.tags)
        route_message(sender_id=self.sender_id,
                      message_text=None,
                      quick_reply=None,
                      postback='UPDATE_PROJECT_PAYLOAD',
                      attachment_type=None,
                      attachment_url=None)
        self.assertNotEqual(
            Maker.objects.get(sender_id=self.sender_id).conversation_stage_id,
            get_conversation_stage_id(conversation_name='menu',
                                      stage_name='menu'))