Ejemplo n.º 1
0
def analyseMessage(psid, message):
    response, status = callWit(message)
    msg_sent_count = 0
    if status:
        #entity like `intent`, `greetings`, `question` etc
        for entity in response:
            logging.info('Entity %s\n' % str(entity))
            entityClass = entityTypes[entity]
            logging.info('Enitity Class: %s\n' % entityClass.__class__.__name__)
            #every entity has a list of entity types like my `intent` has `happiness`
            for entityType in response[entity]:
                logging.info('Checking entityType: %s\n' % entityType)
                method = getattr(entityClass, entityType['value'])
                logging.info('Calling method: %s\n' % method.__name__)
                msgSent = method(psid, entityType['confidence'])
                msg_sent_count += bool(msgSent)

    else:#WitError
        msg = message_dict['wit_error']
        msgSent = sendFBText(psid, msg)
        msg_sent_count += bool(msgSent)

    logging.info("msg_sent_count: %s\n" % msg_sent_count)
    if msg_sent_count == 0:
        msg = message_dict['no_idea']
        sendFBText(psid, msg)
Ejemplo n.º 2
0
 def feature(self, psid, confidence):
     if confidence > 0.80:
         msg = message_dict['features']
         sendFBText(psid, msg)
         msg = message_dict['features1']
         sendFBText(psid, msg)
         msg = message_dict['features2']
         return sendFBText(psid, msg)
Ejemplo n.º 3
0
def toggleUserSubcription(psid, flag=False):
    user = User.objects.get(psid=psid)
    if (flag and not user.subscribed) or (not flag and user.subscribed):
        user.subscribed = flag
        user.save()
        msg = message_dict['activate'] if flag else message_dict['deactivate']
        return sendFBText(psid, msg)
    else:
        msg = 'Your account is already so. 😪'
        return sendFBText(psid, msg)
Ejemplo n.º 4
0
def informUsersAboutNewCompany(data_dict):
    msg = message_dict['new_company'].format(**data_dict)
    print('\n\n\n informUsersAboutNewCompany')
    for user in User.objects.filter(valid=True,
                            subscribed=True,
                            profile_completed=True,
                            course__in=data_dict['course'].split(),
                            department__in=data_dict['department'].split(),
                            purpose__in=data_dict['purpose'].lower().split()):

        sendFBText(user.psid, msg)
Ejemplo n.º 5
0
def newUser(psid):
    data = getUserFromGraphAPI(psid)
    user = User.objects.create(psid=psid,
                            first_name = data['first_name'],
                            last_name = data['last_name'],
                            gender = data['gender'],
                            profile_pic = data['profile_pic'])
    msg = message_dict['welcome']
    sendFBText(psid, msg)
    msg = message_dict['get_email']
    sendFBText(psid, msg)
Ejemplo n.º 6
0
def updateUserAboutThisCompany(data_dict, changed_fields):
    company = Company.objects.get(company_name=data_dict['company_name'])

    msg = ''
    temp = '{0}: {1}\n'
    for field in changed_fields:
        msg += temp.format(field_msg_dict[field], data_dict[field])

    final_msg = message_dict['updated_company'].format(
                                                data_dict['company_name'],
                                                msg,
                                                data_dict['updated_at'])

    for user in User.objects.filter(valid=True,
                            subscribed=True,
                            profile_completed=True,
                            course__in=company.course.split(),
                            department__in=company.department.split(),
                            purpose__in=company.purpose.lower().split()):
        sendFBText(user.psid, final_msg)
Ejemplo n.º 7
0
def updateNewUser(psid):
    user = User.objects.get(psid=psid)
    #logging.info('Gotta update new user %s ', user)
    companies = Company.objects.filter(course__icontains=user.course,
                             department__icontains=user.department,
                             purpose__icontains=user.purpose)

    if len(companies):
         msg = 'Companies opened for you so far:\n\n'
         sendFBText(psid, msg)
    else:
        msg = 'No company is open for you as for now, will inform you when one opens :)'
        return sendFBText(psid, msg)

    for company in companies:
        c = company.__dict__

        msg = c['company_name'] + '\n\n'
        for field in field_msg_dict:
            if c[field]:#if not none
                msg += field_msg_dict[field] + ': ' + c[field] + '\n'

        #logging.info(msg)
        sendFBText(psid, msg)

    msg = "That's it for now, will keep updating you :)"
    return sendFBText(psid, msg)
Ejemplo n.º 8
0
def completeProfile(psid, received_msg):
    user = User.objects.get(psid=psid)
    received_msg = received_msg.strip().split(' ')
    if len(received_msg) != 1:
        msg = message_dict['reg_error']
        return sendFBText(psid, msg)


    value = received_msg[0].lower()

    if '@' in value and not user.email:#it's email and user hasn't set it yet
        if 'itbhu.ac.in' in value:
            temp = value.split('@')[0].split('.')[-1]
            if len(temp) != 5: #like eee15
                msg = message_dict['invalid_email']
                return sendFBText(psid, msg)
            try:
                if int(temp[3:]) >= 15:#let facchas get updates
                    user.purpose = 'internship'
                else:
                    user.purpose = 'placement'
                user.year = int(temp[3:])
                user.department = temp[:3]#eee
                user.email = value
                user.save()
                print('user course: %s\n\n' %user.purpose)
                msg = message_dict['email_set'].format(value)
                sendFBText(psid, msg)
                msg = message_dict['get_course']
                return sendFBText(psid, msg)
            except Exception as e:
                print(e)
                msg = message_dict['invalid_email']
                return sendFBText(psid, msg)
        else:
            msg = message_dict['not_iit_email']
            return sendFBText(psid, msg)


    elif (value=='idd' or value=='btech' or value=='imd') and \
                                not user.course and user.email:
        #true when email is set, course isn't, you got a valid value

        user.course = value
        user.profile_completed = True

        if (value=='idd' or value=='imd') and user.year == 14:
            user.valid=False#idd 4rth yr peeps, zivan ka koi purpose nhi
            user.save()
            msg = message_dict['idd_imd_4th_year']
            return sendFBText(psid, msg)
        user.save()
        msg = message_dict['course_set'].format(value)
        sendFBText(psid, msg)
        updateNewUser(psid)
        msg = message_dict['reg_success']
        return sendFBText(psid, msg)

    else:
        msg = message_dict['reg_error']
        return sendFBText(psid, msg)
Ejemplo n.º 9
0
def gotInactiveUser(psid):
    msg = message_dict['user_invalid']
    sendFBText(psid, msg)
Ejemplo n.º 10
0
 def master(self, psid, confidence):
     if confidence > 0.90:
         msg = message_dict['master']
         return sendFBText(psid, msg)
Ejemplo n.º 11
0
 def true(self, psid, confidence):
     if confidence > 0.80:
         msg = message_dict['greetings']
         return sendFBText(psid, msg)
Ejemplo n.º 12
0
 def abuse(self, psid, confidence):
     if confidence > 0.80:
         msg = message_dict['abuse']
         sendFBText(psid, msg)
         return sendFBText(psid, message_dict['lol'])
Ejemplo n.º 13
0
 def happiness(self, psid, confidence):
     if confidence > 0.60:
         msg = random.choice(['😁', '😃', '😄', '😉', '😊', '😎', '😘', '🙂'])
         return sendFBText(psid, msg)
Ejemplo n.º 14
0
 def help(self, psid, confidence):
     if confidence > 0.80:
         msg = message_dict['help']
         return sendFBText(psid, msg)
Ejemplo n.º 15
0
 def haalchaal(self, psid, confidence):
     if confidence > 0.80:
         msg = message_dict['haalchaal']
         return sendFBText(psid, msg)