Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
plugins
telegram
Commits
08bf4bae
Commit
08bf4bae
authored
2 years ago
by
Aziz Berkay Yesilyurt
Browse files
Options
Download
Email Patches
Plain Diff
add service to items
parent
4c925f58
Pipeline
#11562
passed with stages
in 5 minutes and 13 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
telegram/cli.py
+1
-1
telegram/cli.py
telegram/plugin.py
+4
-4
telegram/plugin.py
telegram/utils.py
+2
-2
telegram/utils.py
with
7 additions
and
7 deletions
+7
-7
telegram/cli.py
+
1
-
1
View file @
08bf4bae
...
...
@@ -30,7 +30,7 @@ def send_message_action(
assert
phone_number
,
"provide a valid phone number either via cli or example_message_config.json"
message
=
Message
(
sendStatus
=
"toSend"
,
service
=
service
,
content
=
content
)
account
=
Account
(
externalId
=
phone_number
)
account
=
Account
(
externalId
=
phone_number
,
service
=
service
)
edge
=
Edge
(
message
,
account
,
"receiver"
)
client
.
bulk_action
(
create_items
=
[
message
,
account
],
create_edges
=
[
edge
])
...
...
This diff is collapsed.
Click to expand it.
telegram/plugin.py
+
4
-
4
View file @
08bf4bae
...
...
@@ -63,7 +63,7 @@ class TelegramPlugin(PluginBase):
chat_id
=
str
(
chat
.
id
)
name
=
chat
.
title
if
not
chat_id
in
self
.
existing_item_ids
[
itemType
]
+
list
(
self
.
items
[
itemType
]):
channel
=
MessageChannel
(
externalId
=
chat_id
,
name
=
name
)
#
service=SERVICE_NAME
channel
=
MessageChannel
(
externalId
=
chat_id
,
name
=
name
,
service
=
SERVICE_NAME
)
self
.
items
[
itemType
][
chat_id
]
=
channel
self
.
add_to_queue
(
items
=
[
channel
])
...
...
@@ -111,7 +111,7 @@ class TelegramPlugin(PluginBase):
items
.
append
(
account
)
if
not
user_id
in
self
.
existing_item_ids
[
itemType2
]
+
list
(
self
.
items
[
itemType2
]):
channel
=
MessageChannel
(
externalId
=
user_id
,
name
=
handle
or
name
)
channel
=
MessageChannel
(
externalId
=
user_id
,
name
=
handle
or
name
,
service
=
SERVICE_NAME
)
self
.
items
[
itemType2
][
user_id
]
=
channel
edges
.
append
(
Edge
(
channel
,
account
,
"receiver"
))
items
.
append
(
channel
)
...
...
@@ -361,8 +361,8 @@ class TelegramPlugin(PluginBase):
query_time
=
int
(
datetime
.
now
().
timestamp
()
*
1000
)
-
5000
msgs_to_send
=
self
.
client
.
search
(
{
"type"
:
"Message"
,
"dateServerModified>="
:
query_time
,
"sendStatus"
:
"toSend"
,
"service"
:
SERVICE_NAME
})
print
(
"MESSAGES TO SEND"
,
msgs_to_send
)
if
len
(
msgs_to_send
)
>
0
:
logger
.
debug
(
"MESSAGES TO SEND"
,
msgs_to_send
)
print
(
msgs_to_send
[
0
].
__dict__
)
for
msg
in
msgs_to_send
:
...
...
@@ -376,4 +376,4 @@ class TelegramPlugin(PluginBase):
self
.
client
.
update_item
(
msg
)
def
add_to_schema
(
self
):
self
.
client
.
add_to_schema
(
Account
,
Message
,
MessageChannel
)
self
.
client
.
add_to_schema
(
Account
,
Message
,
MessageChannel
,
Photo
)
This diff is collapsed.
Click to expand it.
telegram/utils.py
+
2
-
2
View file @
08bf4bae
...
...
@@ -15,7 +15,7 @@ def extract_peer_id_as_str(peer_id):
def
get_external_ids
(
client
,
itemType
:
str
):
external_ids
=
[]
search_filter
=
{
'type'
:
itemType
}
#
, 'service': SERVICE_NAME}
search_filter
=
{
'type'
:
itemType
,
'service'
:
SERVICE_NAME
}
try
:
for
batch
in
client
.
search_paginate
(
search_filter
,
100
):
external_ids
+=
[
m
.
externalId
for
m
in
batch
]
...
...
@@ -23,7 +23,7 @@ def get_external_ids(client, itemType: str):
return
external_ids
def
get_item_by_external_id
(
client
,
itemType
:
str
,
externalId
:
str
):
search_filter
=
{
'type'
:
itemType
,
'externalId'
:
externalId
}
#
, 'service': SERVICE_NAME}
search_filter
=
{
'type'
:
itemType
,
'externalId'
:
externalId
,
'service'
:
SERVICE_NAME
}
result
=
client
.
search
(
search_filter
)
return
result
[
0
]
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets