Commit 08bf4bae authored by Aziz Berkay Yesilyurt's avatar Aziz Berkay Yesilyurt
Browse files

add service to items

parent 4c925f58
Pipeline #11562 passed with stages
in 5 minutes and 13 seconds
Showing with 7 additions and 7 deletions
+7 -7
......@@ -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])
......
......@@ -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)
......@@ -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]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment