sample-app-unfurls icon indicating copy to clipboard operation
sample-app-unfurls copied to clipboard

We cannot resolve error "missing_unfurl_id"

Open m0chi2 opened this issue 4 years ago • 0 comments

Right now I'm trying to send link unfurling to slack channel from AWS lambda(Node.js 14.x) & API Gateway.

I returned a postMessage (using @slack/bolt) including the unfurling_id that was in the value received from Slack via POST,but it did not work.(I tried to return a postMessage (using @slack/bolt) including the unfurling_id that was in the value I received in the POST from Slack, but it didn't work.

Please let me know if you have any advice or hints. Thanky you.

const AWS = require("aws-sdk");
const docClient = new AWS.DynamoDB.DocumentClient();
const { App } = require('@slack/bolt');

exports.handler = async (event, context, callback) => {
    const obj = JSON.parse(JSON.stringify(event));
    const posted_url = obj.event.links[0].url;

    const postMessage = async (data) => {
          const app = new App({
              token: process.env.USER_OAUTH_TOKEN,
              signingSecret: process.env.SIGNING_SECRET
          });
            try {
                const result = app.client.chat.unfurl(data);
                return await result;
            }
            catch (error) {
                console.error(error);
            }
        };

    const setResnponse =  async(userName) => {
      const text = userName + "AAAA";
      const unfurling = {
              "token": process.env.USER_OAUTH_TOKEN,
              "channel": obj.event.channel,
              "ts": obj.event.message_ts,
              "source": "composer",
              "unfurl_id": obj.event.unfurl_id,
              "unfurls": {
                  posted_url: {
                      "blocks": [
                          {
                              "type": "section",
                              "text": {
                                  "type": "mrkdwn",
                                  "text": text
                          }
                      ]
                  }
              },
       };

    const data = setResnponse("BBB")
    const res = await postMessage(data);
    return res;
};
Value obtained from Slack
{
  token: 'QxsXXXXXX',
  team_id: 'YYYYYY',
  api_app_id: 'ZZZZZZZ',
  event: {
    type: 'link_shared',
    user: 'U0XXXXXX',
    channel: 'C0XXXXXX',
    message_ts: '163XXXX.XXXX',
    links: [ [Object] ],
    source: 'conversations_history',
    unfurl_id: 'C0XXXXX.163XXXXX.YYYYYY.4041d4facXXXXXXXXX',
    is_bot_user_member: true,
    thread_ts: '163XXXXX.000200',
    event_ts: '163XXXXXX.274916'
  },
  type: 'event_callback',
  ........
}
Error Code
ERROR    Error: An API error occurred: missing_unfurl_id
    at Object.platformErrorFromResult (/opt/nodejs/node_modules/@slack/web-api/dist/errors.js:51:33)
    at WebClient.apiCall (/opt/nodejs/node_modules/@slack/web-api/dist/WebClient.js:158:28)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async postMessage (/var/task/index.js:106:20)
    at async Runtime.exports.handler (/var/task/index.js:123:21) {
  code: 'slack_webapi_platform_error',
  data: {
    ok: false,
    error: 'missing_unfurl_id',
    response_metadata: { scopes: [Array], acceptedScopes: [Array] }
  }
}

m0chi2 avatar Dec 14 '21 01:12 m0chi2