functions/slack/app.rb
# [START functions_slack_format]
# This is a method of the KGSearch class.
# It takes a raw SearchResponse from the Knowledge Graph Search Service,
# and formats a Slack message.
[START functions_slack_format]
This is a method of the KGSearch class.
It takes a raw SearchResponse from the Knowledge Graph Search Service,
and formats a Slack message.
[ START functions_slack_format ] This is a method of the KGSearch class . It takes a raw SearchResponse from the Knowledge Graph Search Service and formats a Slack message .
def format_slack_message query, response
    result = response.item_list_element&.first&.fetch "result", nil
    attachment =
      if result
        name = result.fetch "name", nil
        description = result.fetch "description", nil
        details = result.fetch "detailedDescription", {}
        { "title"      => name && description ? "#{name}: #{description}" : name,
          "title_link" => details.fetch("url", nil),
          "text"       => details.fetch("articleBody", nil),
          "image_url"  => result.fetch("image", nil)&.fetch("contentUrl", nil) }
      else
        { "text" => "No results match your query." }
      end
    { "response_type" => "in_channel",
      "text"          => "Query: #{query}",
      "attachments"   => [attachment.compact] }
  end
def format_slack_message query , response result = response . item_list_element &. first &. fetch "result" , nil attachment = if result name = result . fetch "name" , nil description = result . fetch "description" , nil details = result . fetch "detailedDescription" , { } { "title" => name && description ? "#{name}: #{description}" : name , "title_link" => details . fetch ( "url" , nil ) , "text" => details . fetch ( "articleBody" , nil ) , "image_url" => result . fetch ( "image" , nil ) &. fetch ( "contentUrl" , nil ) } else { "text" => "No results match your query." } end { "response_type" => "in_channel" , "text" => "Query: #{query}" , "attachments" => [ attachment . compact ] } end
[START functions_slack_format]
This is a method of the KGSearch class.
[ START functions_slack_format ] This is a method of the KGSearch class .
query
<not_specific>
response
<not_specific>