Lloyd | 2020-04-09 18:59:42 UTC | #1
I usually use C#, but working with a team on a Python implementation of the notifications API & struggling with implementing notifications .
I've created an instance of the Notifications API & have created a channel & am attempting to subscribe to a topic.
print('\n* CREATING CHANNEL') createdChannelOk = False try:
Create a new channel
newChannelresponse = apiinstance.postnotificationschannels()
pprint(newChannel_response)
print(newChannelresponse) createdChannelOk = True except ApiException as e: print("Exception when calling NotificationsApi->postnotifications_channels: %s\n" % e)
if (createdChannelOk): print('\n* SUBSCRIBING TO QUEUE')
channel = str(newChannel_response['id'])
myTopic = 'v2.routing.queues.'+queue_id+'.conversations' print(myTopic) body = [myTopic] # list[ChannelTopic] | Body
try:
Replace the current list of subscriptions with a new list.
apiresponse = apiinstance.putnotificationschannelsubscriptions(newChannelresponse['id'], body) pprint(apiresponse) except ApiException as e: print("Exception when calling NotificationsApi->putnotificationschannelsubscriptions: %s\n" % e)
The channel is created successfully, but I get an error trying to subscribe to the topic
CREATING CHANNEL {'connect_uri': 'wss://streaming.mypurecloud.com.au/channels/streaming-0-80b1gi3gjc4msvd0tcrfg9vcl6', 'expires': datetime.datetime(2020, 4, 10, 18, 47, 17, 858000, tzinfo=tzutc()), 'id': 'streaming-0-80b1gi3gjc4msvd0tcrfg9vcl6'}
SUBSCRIBING TO QUEUE v2.routing.queues.f4bf7a5c-d17a-4020-82f7-9bcf3c061722.conversations Traceback (most recent call last): File "C:/PYRIOS/twilio-auto-tester/pyriosQueueNotifications.py", line 73, in <module> apiresponse = apiinstance.putnotificationschannelsubscriptions(newChannelresponse['id'], body) TypeError: 'Channel' object is not subscriptable
So it appears my use of newChannel_response['id'] is incorrect.
If I copy the ChannelId from the output & hard code it, then the subscription (appears to) works fine.
So my question is how do I use the channel Id from create channel response in the subscription request
Thanks
tim.smith | 2020-04-09 19:06:05 UTC | #2
It should just be newChannel_response.id. The response is an instance of the Channel class, not a dictionary.
Lloyd | 2020-04-09 22:14:35 UTC | #3
Ahh, I'm being a muppet; That worked perfectly!
system | 2020-05-10 22:14:39 UTC | #4
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 7518