跳至内容
菜单
此问题已终结

I'm trying to make a function to send a message to a specific user for this in my model I wrote this code


    class SkypeBot(models.Model):
        _name = 'my.skype'
        _inherit = ['mail.thread', 'mail.activity', 'res.users']
        _description = 'My Skype'
    
    
        skype_login = fields.Char('Your skype Login')
        skype_password = fields.Char('Your skype password')
        skype_message = fields.Char(store=True)
    
        @api.multi
        def msg(self, message):
    
            partner_id = self.env['res.users'].search([('id', '=', 2)]).partner_id.id
    
            _logger.info('^^^^^' * 5)
            _logger.warning(partner_id)
            _logger.info('^^^^^' * 5)
    
            self.env['mail.message'].create({'message_type': 'notification',
                                             'subtype': self.env.ref('mail.mt_comment').id,  # subject type
                                             'body': message,
                                             'subject': 'Message subject',
                                             'partner_ids': [(4, partner_id), ],
                                             # partner to whom you send notification
                                             })



I need to connect the odoo environment to thread which I call here so that I can calmly call the msg method from the SkypeBot class and send a message to the user. How to do it right

    class MySkype(skpy.SkypeEventLoop):
        def onEvent(self, event):
            if isinstance(event, skpy.SkypeNewMessageEvent):  
                                                                 
                message = ('New message from user {} at {}: \'{} \''.format(event.msg.userId,
                                                                       event.msg.time.strftime('%H:%M dd. %d.%m.%Y'),
                                                                       event.msg.content))
    
    
                _logger.info('--------'*5)
                _logger.warning(event)
                _logger.info('--------' * 5)
                _logger.warning(message)
                _logger.info('--------' * 5)
    
                sbot = skype_model.SkypeBot()
                sbot.msg(message)
    
    from skpy import Skype
    
    sk = MySkype('+375', '1239qW', autoAck=True)
    thread = threading.Thread(target=sk.loop)
    thread.start()
形象
丢弃
相关帖文 回复 查看 活动
1
6月 20
3892
0
12月 20
3550
1
10月 20
3562
2
12月 23
14903
0
10月 23
33