summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-10-10 08:53:39 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-10-10 08:53:39 +0700
commit9c6e2e8f35f14dda376e543e5b63b0bddee2fd88 (patch)
tree6210f71a62abb55d1be41c48467e167ddb031394
parentdcbb5680c9dd6ecf18eaf3dbbc3af26ac7a47134 (diff)
<iman> update telegram
-rw-r--r--indoteknik_custom/models/stock_picking.py3
-rw-r--r--indoteknik_custom/models/website_telegram.py41
2 files changed, 33 insertions, 11 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index b65d06e4..58eb5d82 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -314,7 +314,8 @@ class StockPicking(models.Model):
telegram_data = {
'tittle': 'Permintaan retur ' + self.name,
'about': 'Permintaan retur ' + self.name,
- 'id_data': self.id
+ 'id_data': self.id,
+ 'username': '@'+self.name.replace('/', '')
}
telegram = request.env['website.telegram'].create(telegram_data)
for pick in self:
diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py
index 45927b73..d67cafc5 100644
--- a/indoteknik_custom/models/website_telegram.py
+++ b/indoteknik_custom/models/website_telegram.py
@@ -12,6 +12,7 @@ class WebsiteTelegram(models.Model):
_name = 'website.telegram'
_description = 'Telegram Channel'
tittle = fields.Char("Channel Title")
+ username = fields.Char("Channel Name")
id_data = fields.Char("Channel ID")
about = fields.Char("Channel Description")
is_broadcast = fields.Boolean("Is Broadcast", default=True)
@@ -30,7 +31,8 @@ class WebsiteTelegram(models.Model):
megagroup=True,
))
channel = result.updates[3].message.peer_id
- username_to_add = ['@imsep81', '6285764475716', '@stephanchrst']
+ # username_to_add = ['@imsep81', '6285764475716', '@stephanchrst']
+ username_to_add = ['@imsep81']
for name in username_to_add:
user_to_add = await client.get_entity(name)
result = await client(functions.channels.InviteToChannelRequest(
@@ -40,6 +42,24 @@ class WebsiteTelegram(models.Model):
message = 'https://erp.indoteknik.com/web#id='+self.id_data+'&action=209&model=stock.picking&view_type=form&cids=1&menu_id=101'
result = await client(SendMessageRequest(channel, message))
+ result = client(functions.channels.UpdateUsernameRequest(
+ channel=channel,
+ username='@indoJaya21'
+ ))
+ print(result.stringify())
+
+ def receive_messages(self):
+ asyncio.run(self._async_receive_messages())
+
+ async def _async_receive_messages(self):
+ async with TelegramClient(StringSession('1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='),
+ 27799517, 'df8ee44b0ed11108245037d47b511201') as client:
+ channel = await client.get_entity(self.username)
+ result = client(functions.channels.GetMessagesRequest(
+ channel=channel,
+ id=channel.chats
+ ))
+ print(result.stringify())
def send_to_telegram(self, message):
# if self.env.all.registry.db_name == 'odoo016':return
@@ -94,14 +114,15 @@ class WebsiteTelegram(models.Model):
print(e)
return None
- def receive_messages(self):
- updates = self.get_updates()
- if updates and 'result' in updates:
- for update in updates['result']:
- if 'text' in update['channel_post']:
- message_text = update['channel_post']['text']
- chat_id = update['channel_post']['chat']['id']
- chat_name = update['channel_post']['chat']['username']
- print(f"Received message: {message_text} from chat_id: {chat_id}, that is: {chat_name}")
+ # def receive_messages(self):
+ # updates = self.get_updates()
+ # if updates and 'result' in updates:
+ # for update in updates['result']:
+ # if 'text' in update['channel_post']:
+ # message_text = update['channel_post']['text']
+ # chat_id = update['channel_post']['chat']['id']
+ # chat_name = update['channel_post']['chat']['username']
+ # print(f"Received message: {message_text} from chat_id: {chat_id}, that is: {chat_name}")
+