Bug in app algorithmia

Asked

Viewed 73 times

1

I’m trying to run the following code:

const  algorithmia = require("algorithmia");

function trigger() {
  const  url = {"url": "https://www.facebook.com/filipedeschamps?epa=SEARCH_BOX"}
  const apiKey = "sim7psIeBatrvpJajm3Dw3uN1hq1"


  const randomTextAuthenticate = algorithmia(apiKey)

  const randomText = randomTextAuthenticate.algo("koverholt/randomtext/0.1.0")

  const randomTextResponse = randomText.pipe(url)

  console.log(randomTextResponse)

  const randomTextResult = randomTextResponse.get()
}

console.log(trigger())

But I get the following mistake:

TypeError: randomTextResponse.get is not a function
at trigger (/home/romis/olavoTrigger/index.js:17:46)
at Object.<anonymous> (/home/romis/olavoTrigger/index.js:21:13)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

1 answer

1


According to the documentation made available by Algorithmia, the method pipe returns a Promise. That way, you need to chain it into a chain of Promises:

const algorithmia = require('algorithmia')

function trigger() {
  const url = { url: 'https://www.facebook.com/filipedeschamps?epa=SEARCH_BOX' }
  const apiKey = 'sim7psIeBatrvpJajm3Dw3uN1hq1'

  const randomTextAuthenticate = algorithmia(apiKey)
  const randomText = randomTextAuthenticate.algo('koverholt/randomtext/0.1.0')

  // Note abaixo que encadeamos o método `then` após o método `pipe`:
  randomText.pipe(url).then((randomTextResult) => {
    const randomTextResult = randomTextResult.get()
    console.log(randomTextResult)
  })
}

trigger()

Note that if you wish, you can also address this problem using async/await:

const algorithmia = require('algorithmia')

async function trigger() {
  const url = { url: 'https://www.facebook.com/filipedeschamps?epa=SEARCH_BOX' }
  const apiKey = 'sim7psIeBatrvpJajm3Dw3uN1hq1'

  const randomTextAuthenticate = algorithmia(apiKey)
  const randomText = randomTextAuthenticate.algo('koverholt/randomtext/0.1.0')

  // Note abaixo que usamos a palavra-chave `await` para aguardar a resolução da Promise:
  const randomTextResult = await randomText.pipe(url)

  // Como a Promise foi resolvida, você pode usar o método `get` diretamente:
  const randomTextResult = randomTextResult.get()
  console.log(randomTextResult)
}

trigger()

Video approach:

Note that this problem was addressed in Filipe’s video. You can see the excerpt here.

Reference:

  • Thank you! It worked!

  • In this case, mark this answer as the solution of the question by clicking the icon in the top left corner of the post. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.