teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

修正

2020/11/26 11:30

投稿

leeev
leeev

スコア20

title CHANGED
File without changes
body CHANGED
@@ -29,42 +29,9 @@
29
29
  }
30
30
  ```
31
31
  ```アクションの結果帰ってくるeventsパラメーター
32
- {
33
- "events": [
34
- {
35
- "type": "postback",
36
- "replyToken": "hoge",
37
- "source": {
38
- "userId": "hoge",
39
- "type": "user"
40
- },
41
- "timestamp": 1606388380238,
42
- "mode": "active",
43
- "postback": {
44
- "data": "action=begin&res=yes"
45
- }
46
- }
47
- ],
48
- "destination": "hoge",
49
- "linebot": {
50
- "events": [
51
- {
52
- "type": "postback",
53
- "replyToken": "hoge",
54
- "source": {
55
- "userId": "hoge",
56
- "type": "user"
57
- },
58
- "timestamp": 1606388380238,
59
- "mode": "active",
60
- "postback": {
61
- "data": "action=begin&res=yes"
62
- }
63
- }
64
- ],
65
- "destination": "hoge"
66
- }
67
- }
32
+ {"events"=>[{"type"=>"postback", "replyToken"=>"hoge", "source"=>{"userId"=>"hoge", "type"=>"user"}, "timestamp"=>1606388380238, "mode"=>"active", "postback"=>{"data"=>"action=begin&res=yes"}}],
33
+ "destination"=>"hoge", "linebot"=>{"events"=>[{"type"=>"postback", "replyToken"=>"hoge", "source"=>{"userId"=>"hoge", "type"=>"user"}, "timestamp"=>1606388380238, "mode"=>"active", "postback"=>{"data"=>"action=begin&res=yes"}}], "destination"=>"hoge"}}
34
+
68
35
  ```
69
36
  ```ここに言語を入力
70
37
  events.each do |event|

3

修正

2020/11/26 11:30

投稿

leeev
leeev

スコア20

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,6 @@
1
1
  messaging apiを勉強しているのですが、以下のjsonの、actionsのdataのaction="begin&res=yes"の部分において、actionを取得したい時はbeginを、resを取得したいときはyesを取得するようにしたいのですが、自分が書いたコードだとなぜかaction='action'、res='res'となってしまいます。
2
2
  ※追記
3
- 2番目のjsonにおいて、action='begin'、res="yes"もしくは"no"のように取得したいです。
3
+ 2番目書いたものにおいて、action='begin'、res="yes"もしくは"no"のように取得したいです。
4
4
  最後に書いたやり方で取得すると、action='action'、res='res'となぜか文字列がそのまま取得されてしまいます。
5
5
  どうにかaction='begin'、res="yes" or "no"と取得できないでしょうか。
6
6
 

2

追記

2020/11/26 11:12

投稿

leeev
leeev

スコア20

title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,11 @@
1
1
  messaging apiを勉強しているのですが、以下のjsonの、actionsのdataのaction="begin&res=yes"の部分において、actionを取得したい時はbeginを、resを取得したいときはyesを取得するようにしたいのですが、自分が書いたコードだとなぜかaction='action'、res='res'となってしまいます。
2
+ ※追記
3
+ 2番目のjsonにおいて、action='begin'、res="yes"もしくは"no"のように取得したいです。
4
+ 最後に書いたやり方で取得すると、action='action'、res='res'となぜか文字列がそのまま取得されてしまいます。
2
- どうにか2番目に書いたコードで、action='begin'、res="yes" or "no"のように取得できないでしょうか。
5
+ どうにかaction='begin'、res="yes" or "no"取得できないでしょうか。
3
6
 
4
7
 
5
- ```ここに言語を入力
8
+ ```送信内容
6
9
  message = {
7
10
  "type": "template",
8
11
  "altText": "this is a confirm template",
@@ -25,7 +28,47 @@
25
28
  }
26
29
  }
27
30
  ```
31
+ ```アクションの結果帰ってくるeventsパラメーター
32
+ {
33
+ "events": [
34
+ {
35
+ "type": "postback",
36
+ "replyToken": "hoge",
37
+ "source": {
38
+ "userId": "hoge",
39
+ "type": "user"
40
+ },
41
+ "timestamp": 1606388380238,
42
+ "mode": "active",
43
+ "postback": {
44
+ "data": "action=begin&res=yes"
45
+ }
46
+ }
47
+ ],
48
+ "destination": "hoge",
49
+ "linebot": {
50
+ "events": [
51
+ {
52
+ "type": "postback",
53
+ "replyToken": "hoge",
54
+ "source": {
55
+ "userId": "hoge",
56
+ "type": "user"
57
+ },
58
+ "timestamp": 1606388380238,
59
+ "mode": "active",
60
+ "postback": {
61
+ "data": "action=begin&res=yes"
62
+ }
63
+ }
64
+ ],
65
+ "destination": "hoge"
66
+ }
67
+ }
68
+ ```
28
69
  ```ここに言語を入力
70
+ events.each do |event|
71
+ #~~~~省略~~~~
29
72
  action = event['postback']['data']['action'] #これだと'begin'ではなく'action'が取得される
30
73
  res = event['postback']['data']['res'] #これだと'yes'ではなく'res'が取得される
31
74
  ```

1

修正

2020/11/26 11:10

投稿

leeev
leeev

スコア20

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- 以下のjsonの、actionsのdataのaction="begin&res=yes"の部分において、actionを取得したい時はbeginを、resを取得したいときはyesを取得するようにしたいのですが、自分が書いたコードだとなぜかaction='action'、res='res'となってしまいます。
1
+ messaging apiを勉強しているのですが、以下のjsonの、actionsのdataのaction="begin&res=yes"の部分において、actionを取得したい時はbeginを、resを取得したいときはyesを取得するようにしたいのですが、自分が書いたコードだとなぜかaction='action'、res='res'となってしまいます。
2
2
  どうにか2番目に書いたコードで、action='begin'、res="yes" or "no"のように取得できないでしょうか。
3
3
 
4
4