Question

Issues with ringcentral-chatbot package

  • 30 March 2021
  • 1 reply
  • 112 views

I am using the node ringcentral-chatbot package along with the ringcentral. I am using the ringcentral-chatbot package to subscribe to and receive webooks, and I am currently getting an exception in the ringcentral-chatbot package when I receive the following webhook

WebHook payload: {"uuid":"2249990457863490969","event":"/restapi/v1.0/glip/posts","timestamp":"2021-03-29T22:49:33.826Z","subscriptionId":"fb6f0643-0eb4-4996-b4dd-96dcecc9181b","ownerId":"292777004","body":{"id":"4790575108","groupId":"616022018","type":"TextMessage","text":"good","creatorId":"292005004","addedPersonIds":null,"creationTime":"2021-03-29T22:49:33.509Z","lastModifiedTime":"2021-03-29T22:49:33.509Z","attachments":null,"activity":null,"title":null,"iconUri":null,"iconEmoji":null,"mentions":null,"eventType":"PostAdded"}}

POST /bot/webhook 200 0 - 0.650 ms

/home/ec2-user/my-bot/node_modules/ringcentral-chatbot/dist/handlers/postAdded.js:30

const group = await bot.getGroup(groupId);

^


TypeError: Cannot read property 'getGroup' of null

at postAdded (/home/ec2-user/my-bot/node_modules/ringcentral-chatbot/dist/handlers/postAdded.js:30:27)

at async /home/ec2-user/my-bot/node_modules/ringcentral-chatbot/dist/apps/bot.js:52:28


Any ideas on what might be causing this?

I have the following defined as environment variables

RINGCENTRAL_SERVER 
RINGCENTRAL_CHATBOT_ADMIN_USERNAME 
RINGCENTRAL_CHATBOT_ADMIN_PASSWORD 
RINGCENTRAL_CHATBOT_EXPRESS_PORT 
RINGCENTRAL_CHATBOT_CLIENT_ID 
RINGCENTRAL_CHATBOT_CLIENT_SECRET
RINGCENTRAL_CHATBOT_SERVER
RINGCENTRAL_APP_REDIRECT_URL
RINGCENTRAL_CHATBOT_DATABASE_CONNECTION_URI
RINGCENTRAL_CHATBOT_AUTH_CODE
I am also using the following code for authentication

const rcsdk = new SDK({
    server: SDK.server.sandbox,
    appKey: process.env.RINGCENTRAL_CHATBOT_CLIENT_ID,
    appSecret: process.env.RINGCENTRAL_CHATBOT_CLIENT_SECRET
});
const platform = rcsdk.platform();

let data = platform.auth().data();
data.token_type = "bearer"
data.expires_in = 1000000
data.access_token = process.env.RINGCENTRAL_CHATBOT_AUTH_CODE
data.refresh_token = 'xxx'
data.refresh_token_expires_in = 1000000
platform.auth().setData(data)


I also setup


1 reply

If you use the chatbot framework, why do you need to write code to do authentication? The framework handles it for you.


I think there is no data in your database, so the bot is null:

https://github.com/ringcentral/ringcentral-chatbot-js/blob/master/src/handlers/postAdded.js#L16


It seems that you are trying the bot on a EC2 server. Does it work on your dev server? Maybe you can try remove and re-add the bot, if the bot doesn't exist in your db.

Reply