T
T
Top6662021-08-30 12:39:25
In contact with
Top666, 2021-08-30 12:39:25

How to display attachments: []?

MessageContext {
  id: 0,
  conversationMessageId: 0,
  peerId: 0,
  peerType: 'chat',
  senderId: 0,
  senderType: 'user',
  createdAt: 0,
  updatedAt: undefined,
  pinnedAt: undefined,
  text: undefined,
  forwards: MessageForwardsCollection(1) [
    MessageContext {
      id: 0,
      conversationMessageId: 0,
      peerId: 0,
      peerType: 'chat',
      senderId: 0,
      senderType: 'user',
      createdAt: 0,
      updatedAt: undefined,
      pinnedAt: undefined,
      text: undefined,
      forwards: MessageForwardsCollection(1) [
        MessageContext {
          id: 0,
          conversationMessageId: 0,
          peerId: 0,
          peerType: 'chat',
          senderId: 0,
          senderType: 'user',
          createdAt: 0,
          updatedAt: undefined,
          pinnedAt: undefined,
          text: undefined,
          forwards: MessageForwardsCollection(0) [],
          attachments: [
            AudioMessageAttachment <audio_message0_0_0000> {
              id: 0,
              ownerId: 0,
              accessKey: '000000',
              duration: 0,
              oggUrl: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.ogg',
              mp3Url: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.mp3',
              url: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.mp3',
              locale: undefined,
              transcript: undefined,
              isTranscriptDone: false
            }
          ],
          isOutbox: false,
          type: 'message',
          subTypes: [
            'message_new'
          ],
          state: {}
        }
      ],
      attachments: [],
      isOutbox: false,
      type: 'message',
      subTypes: [
        'message_new'
      ],
      state: {}
    }
  ],
  attachments: [],
  isOutbox: true,
  type: 'message',
  subTypes: [
    'message_new'
  ],
  state: {}
}



мне нужно вывести только вот это:
attachments: [
            AudioMessageAttachment <audio_message0_0_0000> {
              id: 0,
              ownerId: 0,
              accessKey: '000000',
              duration: 0,
              oggUrl: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.ogg',
              mp3Url: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.mp3',
              url: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.mp3',
              locale: undefined,
              transcript: undefined,
              isTranscriptDone: false
            }
          ],
          isOutbox: false,
          type: 'message',
          subTypes: [
            'message_new'
          ],
          state: {}
        }
      ]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
defriz, 2021-09-01
@Top666

look at how your command looks like, that is, for example, cmd.on(/^test/i, message => {}), just look at what you have written instead of message and then to get any information from the message we do: message.attachments or for example message.text is the text of the message

const attachment = message.attachments
const example = attachment.filter(x => x.text == message.text)[0] //без фильтра почему то не мог получить параметры..

and later we can take any example property, for example, console.log(example.ownerId) // will print the id of the creator of this attachment to the console

A
Alexey Yarkov, 2021-08-30
@yarkov

const data = {
  id: 0,
  conversationMessageId: 0,
  peerId: 0,
  peerType: 'chat',
  senderId: 0,
  senderType: 'user',
  createdAt: 0,
  updatedAt: undefined,
  pinnedAt: undefined,
  text: undefined,
  forwards:  [
     {
      id: 0,
      conversationMessageId: 0,
      peerId: 0,
      peerType: 'chat',
      senderId: 0,
      senderType: 'user',
      createdAt: 0,
      updatedAt: undefined,
      pinnedAt: undefined,
      text: undefined,
      forwards:  [
         {
          id: 0,
          conversationMessageId: 0,
          peerId: 0,
          peerType: 'chat',
          senderId: 0,
          senderType: 'user',
          createdAt: 0,
          updatedAt: undefined,
          pinnedAt: undefined,
          text: undefined,
          forwards:  [],
          attachments: [
             {
              id: 0,
              ownerId: 0,
              accessKey: '000000',
              duration: 0,
              oggUrl: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.ogg',
              mp3Url: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.mp3',
              url: 'https://psv4.userapi.com/c0//u0/audiomsg/d4/0.mp3',
              locale: undefined,
              transcript: undefined,
              isTranscriptDone: false
            }
          ],
          isOutbox: false,
          type: 'message',
          subTypes: [
            'message_new'
          ],
          state: {}
        }
      ],
      attachments: [],
      isOutbox: false,
      type: 'message',
      subTypes: [
        'message_new'
      ],
      state: {}
    }
  ],
  attachments: [],
  isOutbox: true,
  type: 'message',
  subTypes: [
    'message_new'
  ],
  state: {}
};

console.log(data.forwards[0].forwards[0].attachments)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question