2

update !important: The API has changed a lot, this question shouldn't be taken into consideration anymore

I am trying to use the REST api (via Node.js API) to create cards that the user can respond to and create an interaction in this way.

Reading the docs the creator attribute is not really specified anywhere, so I have no idea how to insert that.

Also this video doesn't help. Nor this guide =)

I believe there is an URL I should set as callback somehow? I'd like to know how to get these responses, please.

update

This is the card I am sending.

        {
          bundleId: 'veryuniqueBundle',
          id: 'veryuniqueBundle:reply',
          text: "want to hear moar?",
          menuItems: [
            {action: "REPLY"}
          ]
        }

that's the response I get:

{
    "collection": "timeline",
    "itemId": "119c4dc8-c0ce-4a83-aa76-41aab4e8dbe1",
    "operation": "INSERT",
    "verifyToken": "42",
    "userToken": "id:520ef63cde31145deb000001",
    "userActions": [
        {
            "type": "REPLY"
        }
    ]
}

The problem is, I can't see what the user responded (an text) and the reference to the original card id (or bundle) that was responded to. How can I get those

Fabiano Soriani
  • 8,182
  • 9
  • 43
  • 59

1 Answers1

2

Cards do not provide a direct callback. Instead, when a user selects a menu item it causes the card to be updated with their menu selection. This change subsequently triggers a notification ping to your timeline subscription.

Follow these steps to detect a menu item selection:

  1. Subscribe to notifications for changes in the timeline collection

    {
      "collection": "timeline",
      "userToken": "awesome_kitty",
      "verifyToken": "random_hash_to_verify_referer",
    }
    
  2. Insert a timeline card with a custom menu item

    {
      "text": "Hello world",
      "menuItems": [
        {
          "action": "CUSTOM",
          "id": "complete"
          "values": [{
            "displayName": "Complete",
            "iconUrl": "http://example.com/icons/complete.png"
          }]
        }
      ]
    }
    
  3. Select the item on Glass

  4. Receive the notification on your subscription URL

    {
      "collection": "timeline",
      "itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
      "operation": "UPDATE",
      "userToken": "harold_penguin",
      "userActions": [
        {
          "type": "CUSTOM",
          "payload": "PING"
        }
      ]
    }
    
  5. Do cool stuff in your code

  6. ???
  7. Profit
mimming
  • 13,974
  • 3
  • 45
  • 74
  • 1
    Sorry, I should've been more specific, I meant a card that user use text to reply to {"action": "REPLY"}. I noticed that if it is a bundle the user's answer get's inserted as first card (which is kinda weird, since telling a usually latest is rightmost; but anyway, I think she same logic you listed here applies! (?) Thanks – Fabiano Soriani Aug 08 '13 at 22:53
  • 1
    Yup, bundles are chronological. If you want to manually reorder them, you can change timelineItem.displayTime. You can update existing cards and set later values for displayTime to push the new card to the right. – mimming Aug 12 '13 at 20:28
  • Updated the question, I am using another card, can you take a look? This answer is still useful though, but not the one for my case, I'd recommend keeping. If you want me to I can do another question and re-work this one – Fabiano Soriani Aug 17 '13 at 04:24