incoming-call-pickup subscription works in sandbox but not production

  • 1
  • Problem
  • Updated 4 weeks ago
so I have used the ringcentral python sdk example to make a subscription to the incoming call event. it works great using the sandbox credentials. the app was approved for production. however, when i use the production url and credentials for a valid extension(my desk phone) it does not work.. no error, nothing.. i confirmed the login credentials are correct but it acts as tho no call is coming in when there is a call coming in because my phone is ringing.
Photo of Kevin Nading

Kevin Nading

  • 204 Points 100 badge 2x thumb

Posted 3 months ago

  • 1
Photo of Phong Vu

Phong Vu, Devangelist

  • 5,426 Points 5k badge 2x thumb
Hi Kevin,

Can you post the complete filter you registered for notification?

Something like this "/restapi/v1.0/account/{accountId}/extension/{extensionId}/incoming-call-pickup"

I am afraid that in your sandbox, you login with the admin role and you can get notification for all extensions. And in your production, you might login with a standard user so make sure the incoming call is for that extension only. But this is just my guess. So please post some code and maybe print the log to see if some error happenned.

+ Phong
Photo of Kevin Nading

Kevin Nading

  • 204 Points 100 badge 2x thumb
Hi Phong,

You are correct, thats the exact and complete "filter" i am using.

Yes, in the production I am logging into my own phone with my own credentials to get calls just for my own extension. The incoming call is from an outside line calling into my direct line. I did not try calling into the main line and dialing my extension, I surely would hope its not limited to just extensions dials and not direct line dials.

BTW, my user is a super admin over the entire system which should weed out any permission problems?

thank you for your prompt reply!

Kevin

Photo of Kevin Nading

Kevin Nading

  • 204 Points 100 badge 2x thumb
I just tried dialing my line from an internal phone using just the extension and it also did not call the event. there are no errors
Photo of Phong Vu

Phong Vu, Devangelist

  • 5,396 Points 5k badge 2x thumb
That's weird, I just try my code and it works well with my production extension.

In your case, do you use PubNub or WebHook type? Any error/exception or just nothing happens?

Give my your  email address so I can send you my test code.

+ Phong
Photo of Kevin Nading

Kevin Nading

  • 204 Points 100 badge 2x thumb
using pubnub:
---------------------------------
    def pubnub():
        try:
            s = sdk.create_subscription()     
            s.add_events(['/account/~/extension/~/incoming-call-pickup'])
            s.on(Events.notification, on_message)
            s.register()
----------------------------------
kevinnading@teamsdp.com

no error, just nothing happens as if no call comes in

thank you!
(Edited)
Photo of Phong Vu

Phong Vu, Devangelist

  • 5,426 Points 5k badge 2x thumb
Actually let me post the entire code here. It is not long though.

Put this in your .env file and complete with your credentials:

ENVIRONMENT_MODE=production
CLIENT_ID_SB=
CLIENT_SECRET_SB=

USERNAME_SB=
PASSWORD_SB=

CLIENT_ID_PROD=
CLIENT_SECRET_PROD=

USERNAME_PROD=
PASSWORD_PROD= 
Then here is the .py code:

from multiprocessing import Process
from time import sleep
from ringcentral.subscription import Events
from ringcentral import SDK

import os
from dotenv import Dotenv
dotenv = Dotenv(".env")
os.environ.update(dotenv)


def main():
    if os.getenv("ENVIRONMENT_MODE") == "sandbox":
        sdk = SDK(os.getenv("CLIENT_ID_SB"), os.getenv("CLIENT_SECRET_SB"), 'https://platform.devtest.ringcentral.com')
        platform = sdk.platform()
        fromNumber = os.getenv("USERNAME_SB")
        platform.login(os.getenv("USERNAME_SB"), '', os.getenv("PASSWORD_SB"))
    else:
        sdk = SDK(os.getenv("CLIENT_ID_PROD"), os.getenv("CLIENT_SECRET_PROD"), 'https://platform.ringcentral.com')
        platform = sdk.platform()
        fromNumber = os.getenv("USERNAME_PROD")
        platform.login(os.getenv("USERNAME_PROD"), '', os.getenv("PASSWORD_PROD"))

    def on_message(msg):
        print (msg)
        print(msg['uuid'])

    def pubnub():
        try:
            s = sdk.create_subscription()
            #s.add_events(['/account/~/extension/~/message-store/instant?type=SMS'])
            #s.add_events(['/restapi/v1.0/account/~/presence'])
            s.add_events(['/restapi/v1.0/account/~/extension/~/incoming-call-pickup'])
            s.on(Events.notification, on_message)
            res = s.register()
            try:
                f = open("subid.txt", "w")
                print (res.json().id)
                f.write(res.json().id)
                f.close()
            except Exception as e:
                print (e)
            while True:
                sleep(0.1)

        except KeyboardInterrupt:
            print("Pubnub listener stopped...")

    def unregister():
        try:
            f = open("subid.txt", "r")
            subId = f.read()
            f.close()
            if (len(subId)):
                response = platform.delete('/restapi/v1.0/subscription/%s' % (subId))
                print ("Cancelled old subscription.")
            else:
                print ("empty")
        except Exception as e:
            print (e)

    p = Process(target=pubnub)

    try:
        unregister()
        p.start()
    except KeyboardInterrupt:
        p.terminate()
        print("Stopped by User")

    print("Wait for notification...")


if __name__ == '__main__':
    main()

Remember to create an empty subid.txt file!
Let me know,
+ Phong
(Edited)
Photo of Igor Bebin

Igor Bebin, Official Rep

  • 860 Points 500 badge 2x thumb
Hi Kevin, 

Please ensure that Users have "Notify my Soft Clients" setting enabled. If you an admin, then go to Service Web -> Users -> User -> Call Handling & Forwarding ->  User Hours -> My Desktop & Mobile Apps toggle. 

Also, we have another API for User's Telephony state changes, did you try Presence API and notifications? It allows to subscribe on account Presence changes within single event filter. 

Thanks,
Igor
Photo of Kevin Nading

Kevin Nading

  • 204 Points 100 badge 2x thumb
Thank you Igor, that was exactly the problem. I enabled the "desktop and mobile apps" on that extension and now it works. Sure hope you add that into the documentation so the next guy doesnt spend 2 weeks trying to figure it out. thanks again, and thank you Phong also!
Photo of Chancy Kennedy

Chancy Kennedy

  • 62 Points
Well Kevin, I only spent about 2 hours trying to figure it out until I found your comment, so cheers! You saved me 2 weeks.

Another issue I ran into is that the super admin account when subscribing with /account/~/extension/~ only gets me that extension. I had to actually retrieve an access token with the desired extension and then subscribe to that extension's incoming-call-pickup event. This is using WebHook instead of PubNub.

It seems like the super admin token should be able to subscribe to any extensions events?
Photo of Kevin Nading

Kevin Nading

  • 204 Points 100 badge 2x thumb
let me save you even more time.. I have been notified that the /incoming-call-pickup is being removed and you can use /presence instead (https://developers.ringcentral.com/api-reference#Extension-Presence-Event) and ive switched to it and its better

But be aware you will need to pass it a flag in order to know if the ringing event is outgoing or incoming /presence?detailedTelephonyState=true

I am lead to believe you can catch all extensions from a single admin login using (https://developers.ringcentral.com/api-reference#Account-Presence-Event) i havent had a need to do that so I dont know, seems legit.

And before you break your head, you are unable to catch the ring event of ext1 if the call originated through ext2 that the ext1 is a member of ext2 call handing. I ended up with two listeners.. one for my ext1 and one for the ext2 that im handling calls for during a particular time of the day so i had to code a time map to match the time map in ringcentral.

p.s. on this other endpoint you dont have to have desktop and mobile apps enabled.



Photo of Phong Vu

Phong Vu, Devangelist

  • 5,426 Points 5k badge 2x thumb
Hi Chancy Kennedy,

If you login with the admin user and would like to subscribe for all extensions notification, specify the filter without the extension/~ (i.e. /account/~/). Alternatively, you can read all extensions' id then add them to the filter array as show in the snippet below:

for (var id of extIds){
    var filter = '/restapi/v1.0/account/~/extension/' + id + '/presence?detailedTelephonyState=true'
    eventFilter.push(filter)
  }