def returnEkoId(self, twitter_id):
     if self.checkForExistingTwitterId(twitter_id):
         dbUpdateObject = dbUpdate()
         listOfLinks = dbUpdateObject.selectTwitterLinkId(twitter_id)
         return listOfLinks[5]
     else:
         dbUpdateObject = dbUpdate()
         temp = "TEMP" + str(random.randrange(1000000000, 9999999999))
         if dbUpdateObject.selectEkoId(temp) is not None:
             return self.returnEkoId(twitter_id)
         else:
             dbUpdateObject.insertTwitterLinkId(twitter_id, temp)
             return temp
Пример #2
0
	def returnEkoId(self,facebook_id):
		if self.checkForExistingFacebookId(facebook_id):
			dbUpdateObject=dbUpdate()
			listOfLinks=dbUpdateObject.selectFacebookLinkId(facebook_id);
			return listOfLinks[5];
		else:
			dbUpdateObject=dbUpdate()
			temp="TEMP" + str(random.randrange(1000000000,9999999999))
			if dbUpdateObject.selectEkoId(temp) is not None:
				return self.returnEkoId(facebook_id)
			else:
				dbUpdateObject.insertFacebookLinkId(facebook_id,temp)
				return temp
Пример #3
0
    def on_data(self, data):
    	global lastSentId
        print "x"
        receiveTweet= json.loads(data)
        print receiveTweet['id']
	print receiveTweet['timestamp_ms']
	print receiveTweet['text']
	print receiveTweet['user']['id']
	print receiveTweet['user']['screen_name']
        #mess="Hello! @"+receiveTweet['user']['screen_name']
        #api.update_status(status=mess,in_reply_to_status_id=receiveTweet['id'])
        
	message_body= str(receiveTweet['text']).replace("@rohanuzumaki","");
	twitter_id= str(receiveTweet['user']['id'])
     	linkerObject=linker()
	message_sender= linkerObject.returnEkoId(twitter_id);
	print message_sender 
	message_source=linkerObject.returnMessageSource();
	message_type=linkerObject.returnMessageType(1);
	message_status=linkerObject.returnMessageStatus();
	message_destination=message_source;
	dbUpdateObject=dbUpdate()
	dbUpdateObject.insertReceiveMessage(message_sender,message_body,message_source,message_type,message_status)
	print("Receiving %s from %s" % (message_body,message_sender))
	time.sleep(2);

	#to pick only unprocessed message
	replyToBeSent= dbUpdateObject.selectResponseMessage(message_destination, lastSentId);
	self.replyBack(replyToBeSent)
        return True
Пример #4
0
    def message(self, msg):
        global lastSentId
        if msg['type'] in ('chat', 'normal'):
            message_body = str(msg['body'])
            message_sender = str(msg['from']).split('@')[0]
            linkerObject = linker()
            facebook_id = str(msg['from']).split('@')[0]
            message_sender = linkerObject.returnEkoId(facebook_id)
            print message_sender
            message_body = str(msg['body'])
            message_source = linkerObject.returnMessageSource()
            message_type = linkerObject.returnMessageType(1)
            message_status = linkerObject.returnMessageStatus()
            message_destination = message_source
            dbUpdateObject = dbUpdate()
            dbUpdateObject.insertReceiveMessage(message_sender, message_body,
                                                message_source, message_type,
                                                message_status)
            print("Receiving %s from %s" % (msg['body'], msg['from']))
            s = msg['from']
            time.sleep(2)

            #to pick only unprocessed message
            replyToBeSent = dbUpdateObject.selectResponseMessage(
                message_destination, lastSentId)
            print "erwrfsufchxuchxuhc", replyToBeSent
            self.replyBack(msg, replyToBeSent, s)
Пример #5
0
	def checkForExistingWhatsappId(self,whatsapp_id):
		dbUpdateObject=dbUpdate()
		listOfLinks=dbUpdateObject.selectWhatsappLinkId(whatsapp_id);
		if listOfLinks == None:
			return 0;
		#elif not whatsapp_id in listOfLinks:
			#return 0;
		return 1;
Пример #6
0
	def checkForExistingFacebookId(self,facebook_id):
		dbUpdateObject=dbUpdate()
		listOfLinks=dbUpdateObject.selectFacebookLinkId(facebook_id);
		if listOfLinks == None:
			return 0;
		#elif not facebook_id in listOfLinks:
			#return 0;
		return 1;
 def checkForExistingTwitterId(self, twitter_id):
     dbUpdateObject = dbUpdate()
     listOfLinks = dbUpdateObject.selectTwitterLinkId(twitter_id)
     if listOfLinks == None:
         return 0
     #elif not twitter_id in listOfLinks:
     #return 0;
     return 1
Пример #8
0
	def returnEkoId(self,whatsapp_id,groupMessage):
		if self.checkForExistingWhatsappId(whatsapp_id):
			dbUpdateObject=dbUpdate();
			listOfLinks=dbUpdateObject.selectWhatsappLinkId(whatsapp_id);
			return listOfLinks[5];
		else:
			print "&&&&&&&&&&&&&&&&&&&&&&&&&&"
			dbUpdateObject=dbUpdate()
			print "@@@@@@@@@@@@@@@@@@@@", groupMessage
			if groupMessage==0:
				eko_Id="TEMP" + str(random.randrange(1000000000,9999999999))
			else:
				eko_Id="GRP" + str(random.randrange(1000000000,9999999999))

			if dbUpdateObject.selectEkoId(eko_Id) is not None:
				return self.returnEkoId(whatsapp_id)
			else:
				dbUpdateObject.insertWhatsappLinkId(whatsapp_id,eko_Id)
				return eko_Id
Пример #9
0
 def replyBack(self, msg, replyToBeSent, s):
     global lastSentId
     dbUpdateObject = dbUpdate()
     for reply in replyToBeSent:
         if not reply[5]:
             getFacebookId = linker()
             if (reply[5] == 0):
                 dbUpdateObject.updateResponseMessage(2, reply[0])
                 lastSentId = reply[0]
                 print "Sending %s to %s" % (reply[2], s)
                 resp = reply[2]
                 msg.reply(resp).send()
Пример #10
0
    def onTextMessage(self, messageProtocolEntity):
        global lastSendId
        receipt = OutgoingReceiptProtocolEntity(
            messageProtocolEntity.getId(), messageProtocolEntity.getFrom())
        self.toLower(receipt)
        if not messageProtocolEntity.isGroupMessage() or (
                messageProtocolEntity.isGroupMessage() == 1 and
            (messageProtocolEntity.getBody()[:3] == "eko"
             or messageProtocolEntity.getBody()[:3] == "Eko"
             or messageProtocolEntity.getBody()[:3] == "EKO")):
            #inserting in DB
            linkerObject = linker()
            print "####################################################"
            whatsapp_id = messageProtocolEntity.getFrom(False)
            print whatsapp_id
            if not messageProtocolEntity.isGroupMessage():
                groupMessage = 0
                message_body = messageProtocolEntity.getBody()
            else:
                groupMessage = 1
                participantEkoId = linkerObject.returnEkoId(
                    str(messageProtocolEntity.getParticipant(False)), 0)
                print "@@@@@@@@@@@@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", participantEkoId
                message_body = messageProtocolEntity.getBody(
                )[4:] + "@" + participantEkoId

            print groupMessage
            message_sender = linkerObject.returnEkoId(whatsapp_id,
                                                      groupMessage)
            message_source = linkerObject.returnMessageSource()
            message_type = linkerObject.returnMessageType(1)
            message_status = linkerObject.returnMessageStatus()
            message_destination = message_source
            dbUpdateObject = dbUpdate()
            dbUpdateObject.insertReceiveMessage(message_sender, message_body,
                                                message_source, message_type,
                                                message_status)
            print("Receiving %s from %s" %
                  (message_body, messageProtocolEntity.getFrom(False)))

            time.sleep(2)

            #to pick only unprocessed message
            replyToBeSent = dbUpdateObject.selectResponseMessage(
                message_destination, lastSentId)
            self.replyBack(messageProtocolEntity, replyToBeSent)
Пример #11
0
 def replyBack(self, replyToBeSent):
     print "NAMAN KUMAR AGARWAL \n\n\n\n"
     global lastSentId
     global FacebookID
     dbUpdateObject = dbUpdate()
     linkerObject = linker()
     for reply in replyToBeSent:
         if not reply[5]:
             print reply
             print "\n\n\n\n 	NAMAN KUMAR AGARWAL 5555555555555555\n\n\n\n\n"
             self.FacebookId = linkerObject.returnFacebookId(reply[1])
             print linkerObject.returnFacebookId(reply[1])
             if (reply[5] == 0):
                 dbUpdateObject.updateResponseMessage(2, reply[0])
                 lastSentId = reply[0]
                 #print "Sending %s to %s"%(reply[2]);
                 #resp=reply[2]
                 self.send(unicode(self.FacebookID), reply[2])
Пример #12
0
    def replyBack(self,replyToBeSent):
    	global lastSentId;
    	dbUpdateObject=dbUpdate()
        for reply in replyToBeSent:
            print "RFwpldsgknsdknvsldkngsd"
            if not reply[5]:
	    	linkerObject=linker()
	    	twitterId=linkerObject.returnTwitterId(reply[1])
	    	print twitterId;
    	    	if(reply[5] == 0):
    	    		print "1234567543"
                	dbUpdateObject.updateResponseMessage(3,reply[0]);
                	lastSentId=reply[0]
                	screenName=screen_name(api.lookup_users(twitterId))
                	print screenName;
                	print "Sending %s to %s"%(reply[2],screenName);
                	mess=reply[2]+ " @" + screenName
			api.update_status(status=mess);
Пример #13
0
 def replyBack(self, messageProtocolEntity, replyToBeSent):
     global lastSentId
     dbUpdateObject = dbUpdate()
     for reply in replyToBeSent:
         if not reply[5]:
             getWhatsappId = linker()
             print reply
             print "!@#$%^&*(*&^%$#@"
             whatsapp_id = getWhatsappId.returnWhatsappId(reply[1])
             if (reply[5] == 0):
                 if not messageProtocolEntity.isGroupMessage():
                     outgoingMessageProtocolEntity = TextMessageProtocolEntity(
                         reply[2], to=str(whatsapp_id) + "@s.whatsapp.net")
                 else:
                     outgoingMessageProtocolEntity = TextMessageProtocolEntity(
                         reply[2], to=str(whatsapp_id) + "@g.us")
                 dbUpdateObject.updateResponseMessage(1, reply[0])
                 lastSentId = reply[0]
                 print "Sending %s to %s" % (reply[2], whatsapp_id)
                 self.toLower(outgoingMessageProtocolEntity)
Пример #14
0
    def on_message(self, mid, author_id, author_name, message, metadata):

        global lastSentId
        self.markAsDelivered(author_id, mid)  #mark delivered
        self.markAsRead(author_id)  #mark read

        #if you are not the author, echo
        if str(author_id) != str(self.uid):
            message_body = message
            message_sender = author_id
            linkerObject = linker()
            facebook_id = author_id
            message_sender = linkerObject.returnEkoId(facebook_id)
            #print message_sender
            message_source = linkerObject.returnMessageSource()
            message_type = linkerObject.returnMessageType(1)
            message_status = linkerObject.returnMessageStatus()
            message_destination = message_source
            dbUpdateObject = dbUpdate()
            dbUpdateObject.insertReceiveMessage(message_sender, message_body,
                                                message_source, message_type,
                                                message_status)
            time.sleep(1)
            #to pick only unprocessed message
            replyToBeSent = dbUpdateObject.selectResponseMessage(
                message_destination, lastSentId)
            #print "erwrfsufchxuchxuhc", replyToBeSent

            print "NAMAN KUMAR AGARWAL 1 \n\n\n\n"
            print type(author_id)
            print replyToBeSent
            #self.replyBack(replyToBeSent)
            for reply in replyToBeSent:
                if not reply[5]:
                    if (reply[5] == 0):
                        dbUpdateObject.updateResponseMessage(2, reply[0])
                        lastSentId = reply[0]
                        self.send(
                            unicode(linkerObject.returnFacebookId(reply[1])),
                            reply[2])
Пример #15
0
    def onMediaMessage(self, messageProtocolEntity):
        global lastSentId
        if messageProtocolEntity.getMediaType() == "image":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outImage = ImageDownloadableMediaMessageProtocolEntity(
                messageProtocolEntity.getMimeType(),
                messageProtocolEntity.fileHash,
                messageProtocolEntity.url,
                messageProtocolEntity.ip,
                messageProtocolEntity.size,
                messageProtocolEntity.fileName,
                messageProtocolEntity.encoding,
                messageProtocolEntity.width,
                messageProtocolEntity.height,
                messageProtocolEntity.getCaption(),
                to=messageProtocolEntity.getFrom(),
                preview=messageProtocolEntity.getPreview())

            print("Echoing image %s to %s" %
                  (messageProtocolEntity.url,
                   messageProtocolEntity.getFrom(False)))

            #send receipt otherwise we keep receiving the same message over and over
            self.toLower(receipt)
            self.toLower(outImage)

        elif messageProtocolEntity.getMediaType() == "location":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outLocation = LocationMediaMessageProtocolEntity(
                messageProtocolEntity.getLatitude(),
                messageProtocolEntity.getLongitude(),
                messageProtocolEntity.getLocationName(),
                messageProtocolEntity.getLocationURL(),
                messageProtocolEntity.encoding,
                to=messageProtocolEntity.getFrom(),
                preview=messageProtocolEntity.getPreview())

            print("Echoing location (%s, %s) to %s" %
                  (messageProtocolEntity.getLatitude(),
                   messageProtocolEntity.getLongitude(),
                   messageProtocolEntity.getFrom(False)))

            #send receipt otherwise we keep receiving the same message over and over
            self.toLower(outLocation)
            self.toLower(receipt)

        elif messageProtocolEntity.getMediaType() == "vcard":
            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())
            self.toLower(receipt)
            x = messageProtocolEntity.getCardData()
            received_vcard_number = x.split('TEL:')[1].split("\n")[0]

            #inserting in DB
            linkerObject = linker()
            whatsapp_id = messageProtocolEntity.getFrom(False)
            message_sender = linkerObject.returnEkoId(whatsapp_id, 0)
            message_body = received_vcard_number
            message_source = linkerObject.returnMessageSource()
            message_type = linkerObject.returnMessageType(2)
            message_status = linkerObject.returnMessageStatus()
            message_destination = message_source
            dbUpdateObject = dbUpdate()
            dbUpdateObject.insertReceiveMessage(message_sender, message_body,
                                                message_source, message_type,
                                                message_status)

            print("Receiving %s from %s" %
                  (message_body, messageProtocolEntity.getFrom(False)))

            self.toLower(receipt)

            time.sleep(2)
            #to pick only unprocessed message

            replyToBeSent = dbUpdateObject.selectResponseMessage(
                message_destination, lastSentId)
            self.replyBack(messageProtocolEntity, replyToBeSent)

        elif messageProtocolEntity.getMediaType() == "audio":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())
            self.toLower(receipt)
            outAudio = AudioDownloadableMediaMessageProtocolEntity(
                messageProtocolEntity.getMimeType(),
                messageProtocolEntity.fileHash,
                messageProtocolEntity.url,
                messageProtocolEntity.ip,
                messageProtocolEntity.size,
                messageProtocolEntity.fileName,
                messageProtocolEntity.abitrate,
                messageProtocolEntity.acodec,
                messageProtocolEntity.asampfreq,
                messageProtocolEntity.duration,
                messageProtocolEntity.encoding,
                messageProtocolEntity.origin,
                messageProtocolEntity.seconds,
                to=messageProtocolEntity.getFrom())

            path = str(messageProtocolEntity.url)
            commands.getoutput('wget ' + path)
            fname = path.split('/')[-1]
            commands.getoutput('ffmpeg -i ' + fname + ' ' +
                               fname.split('.')[0] + '.wav')
            r = sr.Recognizer()
            with sr.WavFile(
                    fname.split('.')[0] +
                    '.wav') as source:  # use "test.wav" as the audio source
                audio = r.record(source)  # extract audio data from the file
            try:
                print("Receiving sound. Transcription: " + r.recognize(audio)
                      )  # recognize speech using Google Speech Recognition
            except LookupError:  # speech is unintelligible
                print("Could not understand audio")
                return
                #inserting in DB
                whatsapp_id = messageProtocolEntity.getFrom(False)
                message_sender = linker.returnEkoId(whatsapp_id, 0)
                message_body = r.recognize(audio)
                message_source = linker.returnmessageSource()
                message_type = linker.returnmessageType(2)
                message_status = linker.returnmessagestatus()
                message_destination = message_source
                dbUpdateObject = dbUpdate()
                dbUpdateObject.insertReceiveMessage(message_sender,
                                                    message_body,
                                                    message_source,
                                                    message_type,
                                                    message_status)
                print(
                    "Receiving %s from %s" %
                    (r.recognize(audio), messageProtocolEntity.getFrom(False)))

                self.toLower(receipt)

                time.sleep(2)
                #to pick only unprocessed message

                replyToBeSent = dbUpdateObject.selectResponseMessage(
                    message_destination, self.lastSentId)
                self.replyBack(messageProtocolEntity, replyToBeSent)
Пример #16
0
	def returnFacebookId(self,eko_id):
		print "NAMAN KUMAR AGARWAL 3 \n\n\n\n"
		dbUpdateObject=dbUpdate()
		relate_id=dbUpdateObject.convertEkoIdtoOther(eko_id)
		print relate_id
		return str(relate_id[1])
 def returnTwitterId(self, eko_id):
     dbUpdateObject = dbUpdate()
     relate_id = dbUpdateObject.convertEkoIdtoOther(eko_id)
     return str(relate_id[2])
Пример #18
0
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from brain.brain import Brain
from bot.session import Session
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
from databaseImport.databaseUpdate import DbUpdate as dbUpdate
from dumpMessage.dump import Dump

#class PickMessage(object):


def pickAndProcess(dbUpdateObject, sessionObject, brainObject, dumpObject):
    l = dbUpdateObject.selectResponseMessageLastEntry()
    if (l != None):
        l = dbUpdateObject.selectReceiveMessageById(str(l[0]))
    else:
        l = dbUpdateObject.selectReceiveMessageAll()
    for item in l:
        brainObject.brain1(dbUpdateObject, sessionObject, item, dumpObject)


if __name__ == "__main__":
    dbUpdateObject = dbUpdate()
    sessionObject = Session()
    brainObject = Brain()
    dumpObject = Dump()
    #pickObject=PickMessage();
    sessionObject.learn()
    while (1):
        pickAndProcess(dbUpdateObject, sessionObject, brainObject, dumpObject)
        time.sleep(1)
Пример #19
0
	def returnWhatsappId(self,eko_id):
		print eko_id;
		dbUpdateObject=dbUpdate()
		relateId=dbUpdateObject.convertEkoIdtoOther(eko_id)
		return str(relateId[0])