Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
e4483deb
Commit
e4483deb
authored
Feb 29, 2016
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
introducing conversation notes
parent
5f7ec807
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
80 deletions
+86
-80
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+43
-45
SurveyCommand.php
src/Commands/UserCommands/SurveyCommand.php
+26
-27
Conversation.php
src/Conversation.php
+17
-8
No files found.
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
e4483deb
This diff is collapsed.
Click to expand it.
src/Commands/UserCommands/SurveyCommand.php
View file @
e4483deb
...
...
@@ -60,11 +60,10 @@ class SurveyCommand extends UserCommand
$conversation
=
new
Conversation
(
$user_id
,
$chat_id
,
$this
->
getName
());
//cache data from the tracking session if any
$session
=
$conversation
->
getData
();
if
(
!
isset
(
$session
[
'state'
]))
{
if
(
!
isset
(
$conversation
->
notes
[
'state'
]))
{
$state
=
'0'
;
}
else
{
$state
=
$
session
[
'state'
];
$state
=
$
conversation
->
notes
[
'state'
];
}
//state machine
...
...
@@ -73,35 +72,35 @@ class SurveyCommand extends UserCommand
switch
(
$state
)
{
case
0
:
if
(
empty
(
$text
))
{
$
session
[
'state'
]
=
'0'
;
$conversation
->
update
(
$session
);
$
conversation
->
notes
[
'state'
]
=
0
;
$conversation
->
update
();
$data
[
'text'
]
=
'Type your name:'
;
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardHide
([
'selective'
=>
true
]);
$result
=
Request
::
sendMessage
(
$data
);
break
;
}
$
session
[
'name'
]
=
$text
;
$
conversation
->
notes
[
'name'
]
=
$text
;
$text
=
''
;
// no break
case
1
:
if
(
empty
(
$text
))
{
$
session
[
'state'
]
=
1
;
$conversation
->
update
(
$session
);
$
conversation
->
notes
[
'state'
]
=
1
;
$conversation
->
update
();
$data
[
'text'
]
=
'Type your surname:'
;
$result
=
Request
::
sendMessage
(
$data
);
break
;
}
$
session
[
'surname'
]
=
$text
;
$
conversation
->
notes
[
'surname'
]
=
$text
;
++
$state
;
$text
=
''
;
// no break
case
2
:
if
(
empty
(
$text
)
||
!
is_numeric
(
$text
))
{
$
session
[
'state'
]
=
'2'
;
$conversation
->
update
(
$session
);
$
conversation
->
notes
[
'state'
]
=
2
;
$conversation
->
update
();
$data
[
'text'
]
=
'Type your age:'
;
if
(
!
empty
(
$text
)
&&
!
is_numeric
(
$text
))
{
$data
[
'text'
]
=
'Type your age, must be a number'
;
...
...
@@ -109,14 +108,14 @@ class SurveyCommand extends UserCommand
$result
=
Request
::
sendMessage
(
$data
);
break
;
}
$
session
[
'age'
]
=
$text
;
$
conversation
->
notes
[
'age'
]
=
$text
;
$text
=
''
;
// no break
case
3
:
if
(
empty
(
$text
)
||
!
(
$text
==
'M'
||
$text
==
'F'
))
{
$
session
[
'state'
]
=
'3'
;
$conversation
->
update
(
$session
);
$
conversation
->
notes
[
'state'
]
=
3
;
$conversation
->
update
();
$keyboard
=
[[
'M'
,
'F'
]];
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
...
...
@@ -135,14 +134,14 @@ class SurveyCommand extends UserCommand
$result
=
Request
::
sendMessage
(
$data
);
break
;
}
$
session
[
'gender'
]
=
$text
;
$
conversation
->
notes
[
'gender'
]
=
$text
;
$text
=
''
;
// no break
case
4
:
if
(
is_null
(
$message
->
getLocation
()))
{
$
session
[
'state'
]
=
'4'
;
$conversation
->
update
(
$session
);
$
conversation
->
notes
[
'state'
]
=
4
;
$conversation
->
update
();
$data
[
'text'
]
=
'Insert your home location (need location object):'
;
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardHide
([
'selective'
=>
true
]);
...
...
@@ -150,33 +149,33 @@ class SurveyCommand extends UserCommand
break
;
}
$
session
[
'longitude'
]
=
$message
->
getLocation
()
->
getLongitude
();
$
session
[
'latitude'
]
=
$message
->
getLocation
()
->
getLatitude
();
$
conversation
->
notes
[
'longitude'
]
=
$message
->
getLocation
()
->
getLongitude
();
$
conversation
->
notes
[
'latitude'
]
=
$message
->
getLocation
()
->
getLatitude
();
// no break
case
5
:
if
(
is_null
(
$message
->
getPhoto
()))
{
$
session
[
'state'
]
=
'5'
;
$conversation
->
update
(
$session
);
$
conversation
->
notes
[
'state'
]
=
5
;
$conversation
->
update
();
$data
[
'text'
]
=
'Insert your picture:'
;
$result
=
Request
::
sendMessage
(
$data
);
break
;
}
$
session
[
'photo_id'
]
=
$message
->
getPhoto
()[
0
]
->
getFileId
();
$
conversation
->
notes
[
'photo_id'
]
=
$message
->
getPhoto
()[
0
]
->
getFileId
();
// no break
case
6
:
$conversation
->
stop
();
$out_text
=
'/Survey result:'
.
"
\n
"
;
unset
(
$
session
[
'state'
]);
foreach
(
$
session
as
$k
=>
$v
)
{
unset
(
$
conversation
->
notes
[
'state'
]);
foreach
(
$
conversation
->
notes
as
$k
=>
$v
)
{
$out_text
.=
"
\n
"
.
ucfirst
(
$k
)
.
': '
.
$v
;
}
$data
[
'photo'
]
=
$
session
[
'photo_id'
];
$data
[
'photo'
]
=
$
conversation
->
notes
[
'photo_id'
];
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardHide
([
'selective'
=>
true
]);
$data
[
'caption'
]
=
$out_text
;
$conversation
->
stop
();
$result
=
Request
::
sendPhoto
(
$data
);
break
;
}
...
...
src/Conversation.php
View file @
e4483deb
...
...
@@ -26,11 +26,18 @@ class Conversation
protected
$conversation
=
null
;
/**
*
Data
stored inside the conversation
*
Notes
stored inside the conversation
*
* @var array
*/
protected
$data
=
null
;
protected
$protected_notes
=
null
;
/**
* Notes to be stored
*
* @var array
*/
public
$notes
=
null
;
/**
* Telegram user id
...
...
@@ -78,7 +85,8 @@ class Conversation
protected
function
load
()
{
$this
->
conversation
=
null
;
$this
->
data
=
null
;
$this
->
protected_notes
=
null
;
$this
->
notes
=
null
;
//Select an active conversation
$conversation
=
ConversationDB
::
selectConversation
(
$this
->
user_id
,
$this
->
chat_id
,
1
);
...
...
@@ -95,7 +103,8 @@ class Conversation
}
//Load the conversation data
$this
->
data
=
json_decode
(
$this
->
conversation
[
'data'
],
true
);
$this
->
protected_notes
=
json_decode
(
$this
->
conversation
[
'data'
],
true
);
$this
->
notes
=
$this
->
protected_notes
;
}
return
$this
->
exists
();
...
...
@@ -186,10 +195,10 @@ class Conversation
*
* @return bool
*/
public
function
update
(
$data
)
public
function
update
()
{
if
(
$this
->
exists
())
{
$fields
=
[
'data'
=>
json_encode
(
$
data
)];
$fields
=
[
'data'
=>
json_encode
(
$
this
->
notes
)];
$where
=
[
'status'
=>
'active'
,
'user_id'
=>
$this
->
user_id
,
...
...
@@ -201,7 +210,7 @@ class Conversation
return
true
;
}
}
elseif
(
$this
->
start
())
{
return
$this
->
update
(
$data
);
return
$this
->
update
();
}
return
false
;
...
...
@@ -224,6 +233,6 @@ class Conversation
*/
public
function
getData
()
{
return
$this
->
data
;
return
$this
->
notes
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment