Beispiel #1
0
 def form_valid(self, form):
     chat = form.save(commit=False)
     contact = get_object_or_404(Inbox, pk=self.kwargs.get('pk')) 
     chat.send_message(contact)
     # place a taskscheduel record
     BotTask.make_bottask(owner=chat.owner, name=chat, extra_id=chat.id,
                         task_type=BotTaskType.POSTMESSAGE)
     #print('chat:', chat)
     #return super(ContactChatMessageView, self).form_valid(form)
     return self.AjaxResponse()
Beispiel #2
0
    def check_or_add_campaign_task(self):
        connect_campaigns = Campaign.objects.filter(status=True)
        for connect_campaign in connect_campaigns:
            if connect_campaign.owner.is_now_campaign_active():
                queue_type = ContentType.objects.get_for_model(
                    connect_campaign)
                task_queue = TaskQueue.objects.filter(
                    object_id=connect_campaign.id, queue_type=queue_type)
                contacts = connect_campaign.contacts.all()
                task_type = BotTaskType.POSTMESSAGE if connect_campaign.is_bulk else BotTaskType.POSTCONNECT
                if not task_queue:
                    TaskQueue(owner=connect_campaign.owner,
                              content_object=connect_campaign).save()

                for contact in contacts:
                    try:
                        get_chat_message = ChatMessage.objects.get(
                            owner=connect_campaign.owner,
                            contact=contact,
                            campaign=connect_campaign)

                        if get_chat_message.is_sent and not (
                                get_chat_message.replied_date
                                or get_chat_message.replied_other_date):
                            check_task_type = BotTaskType.CHECKCONNECT if task_type == BotTaskType.POSTCONNECT else BotTaskType.CHECKMESSAGE
                            BotTask.objects.get_or_create(
                                owner=connect_campaign.owner,
                                task_type=check_task_type,
                                extra_id=get_chat_message.id,
                                name=connect_campaign)
                        continue
                    except:
                        if connect_campaign.owner.last_message_send_date == datetime.date.today() and \
                                        connect_campaign.owner.message_count >= min(
                                    MAXIMUM_CAMPAIGN_MESSAGE_PER_ACCOUNT, connect_campaign.owner.message_limit_default):
                            continue

                        if connect_campaign.owner.last_message_send_date != datetime.date.today(
                        ):
                            connect_campaign.owner.last_message_send_date = datetime.date.today(
                            )
                            connect_campaign.owner.message_count = 0
                            connect_campaign.owner.save()

                        message = connect_campaign.format_message(contact)
                        chat_message = ChatMessage(
                            owner=connect_campaign.owner,
                            contact=contact,
                            campaign=connect_campaign,
                            text=message,
                            time=timezone.now())
                        chat_message.save()
                        BotTask(owner=connect_campaign.owner,
                                task_type=task_type,
                                extra_id=chat_message.id,
                                name=connect_campaign)
                        connect_campaign.owner.message_count += 1
                        connect_campaign.owner.save()
Beispiel #3
0
 def post(self, request, pk):
     search_form = SearchForm(request.POST)
     if search_form.is_valid():
         search = search_form.save(commit=False)
         linkedin_user = LinkedInUser.objects.get(pk=pk)
         search.owner = linkedin_user
         search.save()
         BotTask(owner=linkedin_user, name=BotTaskType.SEARCH, task_type=BotTaskType.SEARCH,
                 extra_id=search.id).save()
     return HttpResponseRedirect(reverse('account-search', args=[pk]))
Beispiel #4
0
    def post(self, request):
        if 'email' in request.POST.keys() and 'password' in request.POST.keys(
        ):
            user_email = request.POST['email'].strip()
            user_password = request.POST['password'].strip()
            # # collect membership data of this user
            # membership = Membership.objects.get(user=request.user)
            #
            # # create of get linkedin user

            bot_ip = None
            try:
                is_user = LinkedInUser.objects.get(email=user_email)
                if is_user.status == False:
                    bot_ip = is_user.bot_ip
                    is_user.delete()
                else:
                    return HttpResponse('400', status=400)
            except:
                pass

            linkedin_user = LinkedInUser(user=request.user,
                                         email=user_email,
                                         password=user_password)
            linkedin_user.save()
            if not bot_ip:
                try:
                    bot_ip = FreeBotIP.objects.filter()[:1].get()
                    linkedin_user.bot_ip = bot_ip.bot_ip
                    linkedin_user.save()
                    bot_ip.delete()
                except:
                    pass
            else:
                linkedin_user.bot_ip = bot_ip
                linkedin_user.save()

            BotTask(owner=linkedin_user,
                    task_type=BotTaskType.LOGIN,
                    name='add linkedin account').save()

        return redirect('accounts')
Beispiel #5
0
    def post(self, request):
        if 'pin' in request.POST.keys():
            user_email = request.POST['email'].strip()
            user_password = request.POST['password'].strip()
            # collect membership data of this user
            membership = Membership.objects.get(user=request.user)

            # create of get linkedin user
            linkedin_user, created = LinkedInUser.objects.get_or_create(
                user=request.user, email=user_email, password=user_password)

            linkedin_user.latest_login = datetime.datetime.now()
            linkedin_user.save()
            linkedin_user.membership.add(membership)

            BotTask(owner=linkedin_user,
                    task_type='add account',
                    name='add linkedin account').save()

        return redirect('accounts')
Beispiel #6
0
    def check_or_add_campaign_task(self):
        connect_campaigns = Campaign.objects.filter(status=True)
        for connect_campaign in connect_campaigns:
            if connect_campaign.owner.is_now_campaign_active():
                queue_type = ContentType.objects.get_for_model(
                    connect_campaign)
                task_queue = TaskQueue.objects.filter(
                    object_id=connect_campaign.id, queue_type=queue_type)
                contacts = connect_campaign.contacts.all()
                task_type = BotTaskType.POSTMESSAGE if connect_campaign.is_bulk else BotTaskType.POSTCONNECT
                if not task_queue:
                    TaskQueue(owner=connect_campaign.owner,
                              content_object=connect_campaign).save()

                for contact in contacts:
                    try:
                        ChatMessage.objects.get(owner=connect_campaign.owner,
                                                contact=contact,
                                                campaign=connect_campaign)
                        continue
                    except:
                        message = connect_campaign.connection_message.format(
                            Name=contact.name,
                            FirstName=contact.first_name(),
                            Company=contact.company,
                            Title=contact.title)
                        chat_message = ChatMessage(
                            owner=connect_campaign.owner,
                            contact=contact,
                            campaign=connect_campaign,
                            text=message,
                            time=timezone.now())
                        BotTask(owner=connect_campaign.owner,
                                task_type=task_type,
                                extra_id=chat_message.id,
                                name=connect_campaign)