Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error fetching im channels for the bot #174

Open
nivethan-mdsol opened this issue Apr 17, 2020 · 11 comments
Open

Error fetching im channels for the bot #174

nivethan-mdsol opened this issue Apr 17, 2020 · 11 comments

Comments

@nivethan-mdsol
Copy link

nivethan-mdsol commented Apr 17, 2020

Hi @rampatra
Been using slackbot for an year.
There is a recent change happened Slack directory w.r.t RTM api.

When i try to run, am getting below error:

ERROR

2020-04-18 01:50:19.137 ERROR 94948 --- [           main] m.r.jbot.core.slack.SlackService         : 
Error fetching im channels for the bot: 

org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of me.ramswaroop.jbot.core.slack.models.Error: no String-argument constructor/factory method to deserialize from String value ('missing_scope')
 at [Source: java.io.PushbackInputStream@69b2f8e5; line: 1, column: 21] (through reference chain: me.ramswaroop.jbot.core.slack.models.Event["error"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of me.ramswaroop.jbot.core.slack.models.Error: no String-argument constructor/factory method to deserialize from String value ('missing_scope')
 at [Source: java.io.PushbackInputStream@69b2f8e5; line: 1, column: 21] (through reference chain: me.ramswaroop.jbot.core.slack.models.Event["error"])
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:228) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:213) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:95) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:884) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:868) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:622) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:580) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:312) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at me.ramswaroop.jbot.core.slack.SlackService.getImChannels(SlackService.java:64) [classes/:na]
	at me.ramswaroop.jbot.core.slack.SlackService.connectRTM(SlackService.java:52) [classes/:na]
	at me.ramswaroop.jbot.core.slack.Bot.startRTMAndWebSocketConnection(Bot.java:470) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:365) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:310) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776) [spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) [spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) [spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
	at example.jbot.JBotApplication.main(JBotApplication.java:25) [classes/:na]
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of me.ramswaroop.jbot.core.slack.models.Error: no String-argument constructor/factory method to deserialize from String value ('missing_scope')
 at [Source: java.io.PushbackInputStream@69b2f8e5; line: 1, column: 21] (through reference chain: me.ramswaroop.jbot.core.slack.models.Event["error"])
	at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:261) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1420) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1011) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:366) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:307) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1276) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:159) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:150) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:357) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:148) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789) ~[jackson-databind-2.8.1.jar:2.8.1]
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2913) ~[jackson-databind-2.8.1.jar:2.8.1]
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:225) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	... 35 common frames omitted

2020-04-18 01:50:19.151 ERROR 94948 --- [           main] me.ramswaroop.jbot.core.slack.Bot        : No web socket url returned by Slack.
------Reply from SlckWebHook 
2020-04-18 01:50:20.479  INFO 94948 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1ea9f6af: startup date [Sat Apr 18 01:50:16 IST 2020]; root of context hierarchy
2020-04-18 01:50:20.548  INFO 94948 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/webhook],methods=[GET]}" onto public final org.springframework.http.ResponseEntity me.ramswaroop.jbot.core.facebook.Bot.setupWebhookVerification(java.lang.String,java.lang.String,java.lang.String)
2020-04-18 01:50:20.549  INFO 94948 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/webhook],methods=[POST]}" onto public final org.springframework.http.ResponseEntity me.ramswaroop.jbot.core.facebook.Bot.setupWebhookEndpoint(me.ramswaroop.jbot.core.facebook.models.Callback)
2020-04-18 01:50:20.549  INFO 94948 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/subscribe],methods=[POST]}" onto public final void me.ramswaroop.jbot.core.facebook.Bot.subscribeAppToPage()
2020-04-18 01:50:20.551  INFO 94948 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/slash-command],methods=[POST],consumes=[application/x-www-form-urlencoded]}" onto public me.ramswaroop.jbot.core.slack.models.RichMessage example.jbot.slack.SlackSlashCommand.onReceiveSlashCommand(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
2020-04-18 01:50:20.555  INFO 94948 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2020-04-18 01:50:20.556  INFO 94948 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-04-18 01:50:20.580  INFO 94948 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-18 01:50:20.580  INFO 94948 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-18 01:50:20.620  INFO 94948 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-18 01:50:20.819  INFO 94948 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2020-04-18 01:50:20.898  INFO 94948 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2020-04-18 01:50:20.904  INFO 94948 --- [           main] example.jbot.JBotApplication             : Started JBotApplication in 5.686 seconds (JVM running for 6.288)

Following are Scopes:
Bot Token Scopes
app_mentions:read
channels:history
channels:join
channels:read
chat:write
groups:history
im:history
mpim:history

User Token Scopes:
channels:history
channels:read
channels:write
chat:write
files:read
groups:history
groups:read
groups:write
Note: I tried change the very minimal scopes and re-installed, still facing same error.

@rampatra
Copy link
Owner

Looks like a missing scope issue. Can you pl verify if you added the necessary scopes?

Also, when you said you have been using slackbot for a year, did you mean you have been using jbot for a year? If yes, what version have you been using?

@nivethan-mdsol
Copy link
Author

nivethan-mdsol commented Apr 17, 2020

I'm using version: JBot v 4.1.1-SNAPSHOT
Detailed info:
A year back, I created Bot under custom integration.
(Browse Apps -> Custom Integrations ->Bots)

Steps:

  1. I created a New App
  2. Copied the Bot User OAuth Access Token and keyed into application.properties file(as you mentioned.)
  3. I tweaked a bit and When i ran JBotApplication.java, it ran and gave my expected result.

but this custom bot cannot be Publicly distributed.

So I created a Slack App, which eventually gives me the Bot User OAuth Access Token. when i used this Token, am getting prev. mentioned error:

2020-04-18 04:48:33.529 ERROR 51155 --- [ main] m.r.jbot.core.slack.SlackService : Error fetching im channels for the bot:
.
.
.
2020-04-18 04:48:33.542 ERROR 51155 --- [ main] me.ramswaroop.jbot.core.slack.Bot : No web socket url returned by Slack.

The main reason for this issue is that RTM is not connecting which should get us to Connecting to WebSocket at wss://cerberus-xxxx.lb.slack-msgs.com/websocket/xxxxx
I was going through the recent changes in Slack directory, turns out they are deprecating the scopes which are used for Classic Bot(scope:bot) which helps to connect to RTM.
So i couldn't find the scope:bot neither in Bot Token Scopes nor User Token Scopes.
I tried different latest available scopes which has rtm conjunction, but still error.

Purpose of this Bot: When someone invites this bot to any channel or DMs the keyword: Lesson this bot will Post a Software testing related quotes everytime, to educate the s/w testers like daily quotes and +few other capabilities with different contents. (Not using command and slackIncomingWebhookUrl features.)

@nivethan-mdsol
Copy link
Author

@rampatra
" New Slack apps may not use any Real Time Messaging API method. Create a classic app and use the V1 Oauth flow to use RTM. "
Ref: https://api.slack.com/rtm

@gonzoe
Copy link

gonzoe commented Apr 29, 2020

@rampatra

Bump.

I've only had a few mins across multiple days to look at this. Any insights into what needs to happen to remove the need for RTM from JBot? I assume JBot will not function as a classic app.

@Elfilali-Taoufiq
Copy link

hello @rampatra , any update dor this issue please, i'm facing the same error

@gonzoe
Copy link

gonzoe commented May 11, 2020

If you create a new classic app from scratch here, you can get JBot to work. I could not figure out a way to convert an existing app. Its not an ideal solution if you're trying to build a bot that will pass a security review without lots of hand-waving, but you can get something working until this gets resolved.

@Elfilali-Taoufiq
Copy link

thank you @gonzoe for the help, but a classic app doesn't work for me, Jbot can't connect to slack, it give me the error :
_

No web socket url returned by Slack.

_

@gonzoe
Copy link

gonzoe commented May 11, 2020

If you change any of the scopes, your classic app appears to get promoted automatically to a new app. The Slack docs are not super clear on this. You need to create the classic app and install it without changing the scopes.

@Elfilali-Taoufiq
Copy link

for the installation the application must have scopes, so i added some scopes i order to install it for one time but it stiil give me the error

is there some spescifics scopes that i should add ?

@garyarobinson
Copy link

garyarobinson commented Jun 18, 2020

Look at the url the RestTemplate is hitting;

    public String getImListApi() {
        return this.slackApi + "/im.list?token={token}&limit={limit}&next_cursor={cursor}";
    }

The endpoint is returning a deprecated response

{
    "ok": false,
    "error": "method_deprecated",
    "response_metadata": {
        "messages": [
            "[ERROR] This method is retired and can no longer be used. Please use conversations.list or users.conversations instead. Learn more: https:\/\/api.slack.com\/changelog\/2020-01-deprecating-antecedents-to-the-conversations-api."
        ]
    }
}

That response is getting transformed into what it thinks is the expected response and is throwing a runtime exception.

To reproduce this error go to https://api.slack.com/methods/im.list/test and provide a valid classic bot token.

@rampatra
Copy link
Owner

@garyarobinson but this API should work until Feb 2021. See here:

This method is deprecated. It will stop functioning in February 2021 and will not work with newly created apps after June 10th, 2020.

Or, if a developer has created an app after June 10th then it won't work.

Anyway, I will try to update the API endpoint if I get some time this weekend. PRs are always welcome.

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

No branches or pull requests

5 participants