@staticmethod
    def send_message(message, type_msg, payload, recipient_id, channel_url):
        auth_writer = Twitter.auth_initiative_writer(payload["initiative_id"])
        if auth_writer:
            api = tweepy.API(auth_handler=auth_writer, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
            try:
                # Public Posts
                if type_msg == "PU":
                    response = api.update_status(status=message)
                    logger.info("The post '%s' has been published through Twitter" % message)
                # Reply
                elif type_msg == "RE":
                    response = api.update_status(status=message, in_reply_to_status_id=recipient_id)
                    logger.info("The post '%s' has been sent to %s through Twitter" % (message, payload['author_username']))
                # Direct message
                else:
                    author_id = payload['author_id']
                    response = api.send_direct_message(user_id=author_id, text=message)
                    logger.info("The message '%s' has been sent directly to %s through Twitter" % (message, author_id))
                return {'delivered': True, 'response': Twitter.to_dict(response, channel_url)}
            except tweepy.TweepError as e:
                reason = ast.literal_eval(e.reason)
                logger.error("The post '%s' couldn't be delivered. Reason: %s" % (message, reason[0]['message']))
                return {'delivered': False, 'response': reason}
        else:
            logger.error("The write couldn't be authenticated, the message couldn't be sent.")
            return None
dataset/ETHPy150Open joausaga/reportbytwitter/cparte/social_network.py/Twitter.send_message/original