Ejemplo n.º 1
0
    def message(self, message):
        messenger.send_action(SenderAction(sender_action='mark_seen').to_dict())
        messenger.send_action(SenderAction(sender_action='typing_on').to_dict())

        action = process_message(message)
        res = self.send(action.to_dict(), 'RESPONSE')
        messenger.send_action(SenderAction(sender_action='typing_off').to_dict())
        app.logger.debug('Response: {}'.format(res))
Ejemplo n.º 2
0
 def send_mark_seen(self, recipient_id):
     """Send a message through this channel."""
     print('send mark')
     mark_seen = SenderAction(sender_action='mark_seen')
     self.messenger_client.send_action(mark_seen.to_dict(),
                                       {"sender": {
                                           "id": recipient_id
                                       }})
Ejemplo n.º 3
0
    async def send_action(self, recipient_id: Text, sender_action: Text) -> None:
        """Sends a sender action to facebook (e.g. "typing_on").
        Args:
            recipient_id: recipient
            sender_action: action to send, e.g. "typing_on" or "mark_seen"
        """

        self.messenger_client.send_action(
            SenderAction(sender_action).to_dict(), recipient_id
        )
Ejemplo n.º 4
0
def process_image(url):
    if '.gif' in url:
        return Text(text="Sadly i can't analyze gif files. Lets try it again with a standart image format.")

    #let the user know we're analyzing the image
    app.logger.debug('Image received')
    messenger.send(Text("Analyzing the image...").to_dict(), 'RESPONSE')
    messenger.send_action(SenderAction(sender_action='typing_on').to_dict())

    # first check the image size and type
    error = analyzer.check_image_info(url)
    if error:
        return Text(text=error) 

    # then let the analyzer do its job and get a list of dishes that are visible in the image
    dishes = analyzer.get_response_image(url)
    qrs = dishes_to_quick_reply(dishes)
    if not qrs:
        return Text(text='I didn\'t find any dishes. Try again with a different angle or try writting the dish in Hangul.') 
    return Text(text='Choose a dish for more informations.', quick_replies=qrs)
Ejemplo n.º 5
0
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)

DEFAULT_API_VERSION = "7.0"

bp = Blueprint("messenger", __name__)

# Let us set up a user as a global variable
# Default user values
user = {"first_name": _("Friend"), "locale": "en", "timezone": 0}

typing_on = SenderAction(sender_action="typing_on").to_dict()
typing_off = SenderAction(sender_action="typing_off").to_dict()
mark_seen = SenderAction(sender_action="mark_seen").to_dict()


@babel.localeselector
def get_locale():

    if "locale" in user:
        # ar_AR is not supported so we have to make an exception
        if user["locale"].startswith("ar_"):
            return "ar"

        return user["locale"]
    return "en"
Ejemplo n.º 6
0
 def test_mark_seen(self):
     res = SenderAction(sender_action='mark_seen')
     expected = 'mark_seen'
     assert expected == res.to_dict()
Ejemplo n.º 7
0
 def test_invalid_action(self):
     with pytest.raises(ValueError) as err:
         SenderAction(sender_action='invalid')
     assert str(err.value) == 'Invalid sender_action provided.'
Ejemplo n.º 8
0
 def test_typing_off(self):
     res = SenderAction(sender_action='typing_off')
     expected = 'typing_off'
     assert expected == res.to_dict()
Ejemplo n.º 9
0
 def test_mark_seen(self):
     res = SenderAction(sender_action='mark_seen')
     expected = 'mark_seen'
     assert expected == res.to_dict()
Ejemplo n.º 10
0
 def test_typing_off(self):
     res = SenderAction(sender_action='typing_off')
     expected = 'typing_off'
     assert expected == res.to_dict()
Ejemplo n.º 11
0
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

DEFAULT_API_VERSION = "7.0"

bp = Blueprint('messenger', __name__)

# Let us setup user as global variable
user = {}

typing_on = SenderAction(sender_action='typing_on').to_dict()
typing_off = SenderAction(sender_action='typing_off').to_dict()
mark_seen = SenderAction(sender_action='mark_seen').to_dict()


@babel.localeselector
def get_locale():
    if not user == {}:
        return user['locale']
    return 'en'


@babel.timezoneselector
def get_timezone():
    if not user == {}:
        return user['timezone']