Bolt-js: How to publish home or user views.publish with bolt?

Created on 12 Dec 2019  路  6Comments  路  Source: slackapi/bolt-js

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version:

node version:

OS version(s):

Steps to reproduce:

const app = new App({
logLevel: LogLevel.DEBUG,
token: token,
signingSecret: sign_secret,

});
const result = await app.client.views.publish({
token: token,
user_id: userID,
view: view
});

Expected result:

New view updates on user home

Actual result:

TypeError: app.client.views.publish is not a function

Attachments:

NIL

needs info question

All 6 comments

Hey @johnsonyick!

What version of bolt are you running?

hi @stevengill
sorry for my late response.
my bolt version is 1.4.1

馃憢Hello @johnsonyick
Could you try the following example? It should work for you.

Although I'm not sure about what your actual code looks like, one thing I can suggest by checking the given information here is that app.client.views.publish needs to be called inside a listener as below. It doesn't work at the top level of your source code.

// subscribe an event and add a corresponding listener for it
app.event('app_home_opened', async ({ event, context }) => {
  const yourView = {
    "type": "home",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "This is a mrkdwn section block :ghost: *this is bold*, and ~this is crossed out~, and <https://google.com|this is a link>"
        }
      }
    ]
  };
  const result = await app.client.views.publish({
    token: context.botToken,
    user_id: event.user,
    view: yourView
  });
});

hi @seratch
i was trying by the example before, but it states app.client.views.publish is not a function that's why I asked here.

@johnsonyick views.publish is available in @slack/web-api version 5.3.0 or newer. I believe your app depends on an older version of it. Upgrading the version of the npm module addresses the problem.

@seratch wow, you saved me a day! it's fixed by updating @slack/web-api . thanks very much!

Was this page helpful?
0 / 5 - 0 ratings