Get Channel Id for Notification subscription

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
    newChannel_response = api_instance.post_notifications_channels()
    # pprint(newChannel_response)
    print(newChannel_response)
    createdChannelOk = True
except ApiException as e:
    print("Exception when calling NotificationsApi->post_notifications_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.
        api_response = api_instance.put_notifications_channel_subscriptions(newChannel_response['id'], body)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling NotificationsApi->put_notifications_channel_subscriptions: %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>
    api_response = api_instance.put_notifications_channel_subscriptions(newChannel_response['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

It should just be newChannel_response.id. The response is an instance of the Channel class, not a dictionary.

Ahh, I'm being a muppet; That worked perfectly!

  • Thanks Tim
1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.