-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsalesforce_platform_events.py
39 lines (32 loc) · 1.21 KB
/
salesforce_platform_events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import asyncio
from aiosfstream import SalesforceStreamingClient
from dotenv import dotenv_values
# https://medium.com/tech-force/subscribe-to-salesforce-platform-events-with-python-2a3acbe9743c
# https://github.com/robertmrk/aiocometd/pull/20
config = dotenv_values(".env")
consumer_key = config["consumerkey"]
consumer_secret = config["consumersecret"]
username = config["username"]
password = config["password"]
security_token = config["security_token"]
channel_replay_id = {
"HR_Shipping_Address_PE__e": -1,
}
async def subscribeToSalesforce():
async with SalesforceStreamingClient(
consumer_key=consumer_key,
consumer_secret=consumer_secret,
username=username,
password=password+security_token,
sandbox=True,
) as client:
for channel, replayid in channel_replay_id.items():
await client.subscribe(f"/event/{channel}")
# listen for incoming messages
async for message in client:
topic = message["channel"]
data = message["data"]
print(f"{topic}: {data}")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(subscribeToSalesforce())