-3

So, as I said I need to to do the following in a messenger bot using Chatfuel.

  1. Get an input from the user
  2. Save it in a "user input" in Chatfuel
  3. Take this input and search in the first row in google sheet
  4. If found return the "text" in the second row in messenger
  5. If not, return a saved block from Chatfuel

I know how to do the first two steps but I struggle from the third.

My question is How to do the last three steps using any of Python, JSON or Chatfuel integrations.


I had searched for any source to learn something that helps me but I only ended up watched 10+ videos about chatfuel, google spreedsheets, APIs & JSON. And nothing led me to an answer, I even tried to ask in a programming facebook group but no answer also.

Boho
  • 3
  • 2
  • 1
    _"It would be wonderful if someone wrote the whole code that I need from the third step xD"_ You seem to have dramatically misunderstood where you are, or what Stack Overflow is. Please take the [tour] and read about what's on-topic in the [help/on-topic]. – ChrisGPT was on strike May 25 '17 at 23:16
  • Sorry for misunderstanding "what Stack Overflow" is, I just watched some videos talking about JSON and had some coding experience with python and actually I'm searching from yesterday but didn't found anything that can really help me. – Boho May 25 '17 at 23:25

1 Answers1

0

This script will search for the parameter in row one and return the value in the same column from row 2.

function searchFirstTwoRows(s)
{
  var s = (typeof(s) != 'undefined')?s:'';
  var rngA = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
  var r = '';
  if(s)
  {
    for(var i=0;i<rngA[0].length;i++)
    {
      if(rngA[0][i]==s)
      {
        r=(rngA[1][i] != 'undefined')?rngA[1][i]:'';
        break;
      }
    }
  }
  return r;
}

Dealing with Messenger and Chatfuel is up to you.

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • This will save me lot of searching, I was losing the hope & was about to shift to hard code the bot and make all the stuff using host, node.js & others.. Thanks. – Boho May 31 '17 at 01:11