Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Microsoft Teams not displaying the bot reply after some time #1141

Closed
narenderpal opened this issue Nov 21, 2017 · 15 comments
Closed

Microsoft Teams not displaying the bot reply after some time #1141

narenderpal opened this issue Nov 21, 2017 · 15 comments

Comments

@narenderpal
Copy link

Hi,

I am not sure if this is an issue with botkit per say, but noticing an unexpected behavior while used with Microsoft Teams (With Slack, no such behavior observed).

I have a very basic Teams bot, exactly, as described at https://github.com/howdyai/botkit/blob/master/docs/readme-teams.md. I only added some console.log messages just before the bot replies.

The bot is hosted in AWS as an ECS service. It works fine for about an hour and a half. After that, Teams does not display the messages from the bot. I tried with bot the paid and developer versions of Microsoft Teams.

From the console messages I added, I can see that the bot is replying to the requests from Teams. If I restart the bot, the communication again works for next 1.5 hours.

Any clue on what might be happening?

Thanks!

@peterswimm
Copy link
Contributor

Maybe your ECS instance is idling and timing out? There are a few threads here from users who ran into trouble hosting on Amazon, try searching the issue archive.

Maybe you would have better luck hosting it on Glitch
https://glitch.com/~botkit-teams

@narenderpal
Copy link
Author

@peterswimm I found similar issues reported earlier for Slack Bot- #442 #276

So just thinking if we are running into a similar issue in Teams Bot.
I am using Botkit version 0.6.4 , Node version 6.9.5

@narenderpal
Copy link
Author

narenderpal commented Nov 21, 2017

@peterswimm I hosted botkit-starter-teams bot on Glitch. It works fine for few hours and after that I don't get response from bot in Teams. I see Error loading user profile info: User not found error in glitch project logs.

REQ >  /teams/receive
Error loading user profile info:  User not found

info: >   [End]  5  Conversation with  29:1AQMAftWtvoevGMnHMw5zaIrFUlXc91U-3OVn2gM4xOIcrWBgSHrlOReHL3bYUwdSx7thDD9Vjj_0xq42B9pijA in a:1GqF-eTIzCo0Y9kiIb_VqotcouKbEJKWqeMeBFamvOF_9rtBJdGLyok1vw_AmSoMaocNEm_qi3zXePlEsHIWFxksx9hefebYKCYZrfBianbu00o2ZWHCTtUCL3PUez-le

info: [End]  5  Task for  29:1AQMAftWtvoevGMnHMw5zaIrFUlXc91U-3OVn2gM4xOIcrWBgSHrlOReHL3bYUwdSx7thDD9Vjj_0xq42B9pijA in a:1GqF-eTIzCo0Y9kiIb_VqotcouKbEJKWqeMeBFamvOF_9rtBJdGLyok1vw_AmSoMaocNEm_qi3zXePlEsHIWFxksx9hefebYKCYZrfBianbu00o2ZWHCTtUCL3PUez-le

@narenderpal
Copy link
Author

narenderpal commented Nov 21, 2017

screen shot 2017-11-21 at 7 17 29 pm

Bot stops responding..

@narenderpal
Copy link
Author

narenderpal commented Nov 21, 2017

screen shot 2017-11-21 at 7 18 55 pm

Error is glitch logs..

@narenderpal
Copy link
Author

narenderpal commented Nov 21, 2017

After bot restart, the communication again works for few hours and no errors in logs.
screen shot 2017-11-21 at 7 25 15 pm

screen shot 2017-11-21 at 7 24 58 pm

@peterswimm
Copy link
Contributor

Ah yes the timeout question. You should use botkit storage to save your state on a timeout, so it can cleanly resume if a user leaves in the middle of a conversation. We have an article on working with data and studio you might find useful"
https://botkit.groovehq.com/knowledge_base/topics/how-to-store-data-for-your-users

@narenderpal narenderpal changed the title Teams not displaying the bot reply after some time Microsoft Teams not displaying the bot reply after some time Nov 22, 2017
@narenderpal
Copy link
Author

narenderpal commented Nov 24, 2017

@peterswimm It is an access token issue. The token that bot generate using login.microsoftonline.com/common/oauth2/v2.0/token to access Microsoft Teams API has a lifespan of 1 hour. Teams Botkit library api (Teams.js TeamsAPI.js`) do not validate/refresh token on expiry. So after an hour of uptime when bot try to use the same token to get user profile information from MS Teams (getUserById) it fails with 401. Since bot reply message doesn't contain user information, message is not reaching Microsoft Teams client. After bot restart/redeploy the new token gets generated and communication works again for 1 hour.
getuserfromteams
accesstoken-401

@billbliss
Copy link

Good detective work @narenderpal - I was about to suggest it was a refresh token issue.

@peterswimm
Copy link
Contributor

@narenderpal Care to submit a PR to fix this? @billbliss Hi!

@auberryberry
Copy link
Contributor

Hey @narenderpal did you get a PR for this, I'm also seeing the same issue, waaaa!!! If no I can have a crack, I've also got a documentation update I owe BotKit :) I just found this post after getting into the API and coming to the same conclusion.

@auberryberry
Copy link
Contributor

@peterswimm setTimeout?, every 50mins? Teams.js

function tokenHandler(err) { if (err) { // this is a fatal error - could not create a Teams API client throw new Error(err); } setTimeout(controller.api.getToken(tokenHandler), 3000000); }; controller.api.getToken(tokenHandler);

@auberryberry
Copy link
Contributor

To follow up, I fixed this last night, bot stayed up all night which was great, I'll write some test coverage and submit a PR.

@peterswimm
Copy link
Contributor

Please do, and link this thread!

@auberryberry
Copy link
Contributor

auberryberry commented Jan 25, 2018

PR fixing the behaviour and a bit of coverage #1230

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants