Esempio n. 1
0
def receive_message():
    if request.method == 'GET':
        """Before allowing people to message your bot, Facebook has implemented a verify token
        that confirms all requests that your bot receives came from Facebook."""
        token_sent = request.args.get("hub.verify_token")
        return verify_fb_token(token_sent)
    #if the request was not get, it must be POST and we can just proceed with sending a message back to user
    else:
        # get whatever message a user sent the bot
        output = request.get_json()
        for event in output['entry']:
            print(event)
            messaging = event['messaging']  #messaging
            for message in messaging:
                if message.get('message'):
                    #Facebook Messenger ID for user so we know where to send response back to
                    recipient_id = message['sender']['id']
                    if message['message'].get('text'):
                        msg_input = message['message'].get('text')
                        dict_count_thai = isthai(msg_input)
                        response_sent_text = get_message()
                        if dict_count_thai['thai'] > 0:
                            list_tokenized = word_tokenize(msg_input,
                                                           engine='newmm')
                            response_sent_text = ' '.join(list_tokenized)
                        send_message(recipient_id, response_sent_text)
                        #send_message("1834191463278166", response_sent_text)
                    #if user sends us a GIF, photo,video, or any other non-text item
                    if message['message'].get('attachments'):
                        response_sent_nontext = get_message()
                        send_message(recipient_id, response_sent_nontext)
    return "Message Processed"
Esempio n. 2
0
def getSymbol(lists):
    for i in range(len(lists)):
        if isthai(lists[i])['thai'] == 0:
            return lists[i].upper()
    return 0
Esempio n. 3
0
 def test_isthai(self):
     self.assertEqual(isthai('ประเทศไทย'), {'thai': 100.0})
Esempio n. 4
0
def checkth(lists):
    for i in range(len(lists)):
        if isthai(lists[i])['thai'] == 0:
            return lists[i]
    return 0
Esempio n. 5
0
	def test_isthai(self):
		self.assertEqual(isthai('ประเทศไทย'),{'thai': 100.0})