ES6 async await

javascript
bots

#1

Hello world!

First time posting here, I am trying to make a simple bot that will like and retweet on a keyword, I’d like to use async await and I have accomplished that for a tweet, with this:

import Twiter from 'twitter'
import config from './config'
import {
  getFunName
} from './helpers/helpers'
import searchResult from './helpers/search'

const client = new Twiter(config.twitter)

const tweetNow = async (txt) => {
  try {
    await client.post('statuses/update', { status: txt })
    console.log(txt)
  } catch (err) {
    console.log(err)
  }
}

So far so goo, now I’d like to be able to search on a keyword, which I do with:

import Twiter from 'twitter'
import config from '../config'
import {
  rando
} from './helpers'
import params from './parameters'

const client = new Twiter(config.twitter)

const searchResult = async () => {
  let res
  try {
    res = await client.get('search/tweets', params)
  } catch (err) {
    console.log('ERROR :', err)
  }
  return rando(res.statuses).id_str
}

export default searchResult

That will work to return an id string of the search query.

So now I’d like to favourite and retweet using the same sort syntax:

import Twiter from 'twitter'
import config from '../config'
import searchId from './search'
import params from './parameters'

const client = new Twiter(config.twitter)

const retweet = async () => {
  let res
  try {
    res = await client.post(`statuses/retweet/${searchId()}`)
  } catch (err) {
    console.log('ERR :', err, 'SEARCH ID: ', searchId())
  }
  console.log('RES :', res)
}

I have tried several different ways to achieve this none with any success, is anyone able to give me some pointers on where I may be going wrong??

Here is some of the error output for the above search:

ERR : TypeError: Cannot read property 'base' of undefined
    at Twitter.__request (/home/ubuntu/workspace/twitter-bot-bootstrap/node_modules/twitter/lib/twitter.js:116:20)
    at Twitter.post (/home/ubuntu/workspace/twitter-bot-bootstrap/node_modules/twitter/lib/twitter.js:240:15)
    at retweet (/home/ubuntu/workspace/twitter-bot-bootstrap/src/helpers/retweet.js:11:24)
    at Object.<anonymous> (/home/ubuntu/workspace/twitter-bot-bootstrap/src/bot.js:33:1)
    at Module._compile (module.js:571:32)
    at loader (/home/ubuntu/workspace/twitter-bot-bootstrap/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/ubuntu/workspace/twitter-bot-bootstrap/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3) SEARCH ID:  Promise { <pending> }
RES : undefined

I see that SEARCH ID: Promise { <pending> } is in there as a promise but was under the impression that async await will resolve this synchronously

Feedback greatly appreciated :+1: