Skip to content

Commit

Permalink
Allow images to be sent in Messenger (facebookresearch#1408)
Browse files Browse the repository at this point in the history
* allow images in messenger

* another check
  • Loading branch information
klshuster authored Jan 31, 2019
1 parent 1dbf9e0 commit bdf48ae
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions parlai/messenger/core/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def put_data(self, message):
'sticker_sender': message.get('sticker_sender', None),
'img_attempt': img_attempt,
}
if img_attempt and self.data.get('allow_images', False):
action['image_url'] = message['message'].get('image_url')
action['attachment_url'] = message['message'].get('attachment_url')
self.msg_queue.put(action)

def set_stored_data(self):
Expand Down Expand Up @@ -137,7 +140,7 @@ def act(self, timeout=None):
# Get a new message, if it's not None reset the timeout
msg = self.get_new_act_message()
if msg is not None:
if msg.get('img_attempt'):
if msg.get('img_attempt') and not self.data.get('allow_images', False):
# Let agent know that they cannot send images if they
# attempted to send one
msg = None
Expand All @@ -146,7 +149,8 @@ def act(self, timeout=None):
'Please try with a text-only message.',
'episode_done': True}
self.observe(act)
elif not msg.get('text'):
elif (not msg.get('text')
and not (msg.get('image_url') or msg.get('attachment_url'))):
# Do not allow agent to send empty strings
msg = None

Expand Down

0 comments on commit bdf48ae

Please sign in to comment.