Ruby Rails,从 Graphql 获取数据并将其发布到 Facebook-messenger

Ruby on Rails, taking data from Graphql and posting on it to Facebook-messenger

  $message_text = message.text
  module STAPI
    HTTP = GraphQL::Client::HTTP.new("API_ADDRESS")
    Schema = GraphQL::Client.load_schema(HTTP)
    Client = GraphQL::Client.new(schema: Schema,execute: HTTP)
  end

  module Sticker
    Query = STAPI::Client.parse <<-'GRAPHQL'
      {
        stickers(query: "#{$message_text}", first: 21, after: "") {
          edges {
            node {
              fileUrl(fullWatermarked: true)
            }
          }
        }
      }
    GRAPHQL
  end

  result = STAPI::Client.query(Sticker::Query)

首先,这是一个信使机器人,通过这个信使机器人,我正在接受用户输入,我正在我们的数据库中搜索输入,然后我 post 与输入相关的东西。

因此,我无法在代码中进行搜索,因为我认为 query: "#{$message_text}" 已损坏。

我用 message.text 接受用户输入。这个输入是这样的 'Hello'(带有 ')。但是我需要给 query: "#{$message_text}" 这样的部分 "Hello"(with ")。我怎样才能给 messenger.text 来查询这样的部分 "Hello"

我相信你已经知道如何根据你在 . For others facing the same problem, take a look at variables 中写的内容来完成这项工作。你的例子将变成如下:

$message_text = message.text
module STAPI
  HTTP = GraphQL::Client::HTTP.new("API_ADDRESS")
  Schema = GraphQL::Client.load_schema(HTTP)
  Client = GraphQL::Client.new(schema: Schema,execute: HTTP)
end

module Sticker
  Query = STAPI::Client.parse <<-'GRAPHQL'
    query Q($message: String) {
      stickers(query: $message, first: 21, after: "") {
        edges {
          node {
            fileUrl(fullWatermarked: true)
          }
        }
      }
    }
  GRAPHQL
end

result = STAPI::Client.query(Sticker::Query, variables: {message_text: $message_text})