File tree 6 files changed +140
-0
lines changed
src/MessageBird/Objects/Conversation
6 files changed +140
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ // Initiates a conversation by sending a first message. This example uses a hsm message.
4
+
5
+ require (__DIR__ . '/../../autoload.php ' );
6
+
7
+ $ messageBird = new \MessageBird \Client ('YOUR_ACCESS_KEY ' ); // Set your own API access key here.
8
+
9
+ $ content = new \MessageBird \Objects \Conversation \Content ();
10
+
11
+ $ hsm = new \MessageBird \Objects \Conversation \HSM \Message ();
12
+
13
+ $ hsmParams = new \MessageBird \Objects \Conversation \HSM \Params ();
14
+ $ hsmParams ->default = 'YOUR TEMPLATE PARAM ' ;
15
+
16
+ $ hsmLanguage = new \MessageBird \Objects \Conversation \HSM \Language ();
17
+ $ hsmLanguage ->policy = \MessageBird \Objects \Conversation \HSM \Language::DETERMINISTIC_POLICY ;
18
+ //$hsmLanguage->policy = \MessageBird\Objects\Conversation\HSM\Language::FALLBACK_POLICY;
19
+ $ hsmLanguage ->code = 'YOUR LANGUAGE CODE ' ;
20
+
21
+ $ hsm ->templateName = 'YOUR TEMPLATE NAME ' ;
22
+ $ hsm ->namespace = 'YOUR NAMESPACE ' ;
23
+ $ hsm ->params = array ($ hsmParams );
24
+ $ hsm ->language = $ hsmLanguage ;
25
+ $ content ->hsm = $ hsm ;
26
+
27
+ $ message = new \MessageBird \Objects \Conversation \Message ();
28
+ $ message ->channelId = 'YOUR CHANNEL ID ' ;
29
+ $ message ->content = $ content ;
30
+ $ message ->to = 'YOUR MSISDN ' ;
31
+ $ message ->type = 'hsm ' ;
32
+
33
+ try {
34
+ $ conversation = $ messageBird ->conversations ->start ($ message );
35
+
36
+ var_dump ($ conversation );
37
+ } catch (\Exception $ e ) {
38
+ echo sprintf ("%s: %s " , get_class ($ e ), $ e ->getMessage ());
39
+ }
Original file line number Diff line number Diff line change 4
4
5
5
use JsonSerializable ;
6
6
use MessageBird \Objects \Base ;
7
+ use MessageBird \Objects \Conversation \HSM \Message as HSMMessage ;
7
8
8
9
/**
9
10
* Represents a Message object's actual content. Formatted depending on type.
@@ -16,6 +17,7 @@ class Content extends Base implements JsonSerializable
16
17
const TYPE_LOCATION = 'location ' ;
17
18
const TYPE_TEXT = 'text ' ;
18
19
const TYPE_VIDEO = 'video ' ;
20
+ const TYPE_HSM = 'hsm ' ;
19
21
20
22
/**
21
23
* @var string[]
@@ -47,6 +49,11 @@ class Content extends Base implements JsonSerializable
47
49
*/
48
50
public $ video ;
49
51
52
+ /**
53
+ * @var HSMMessage
54
+ */
55
+ public $ hsm ;
56
+
50
57
/**
51
58
* @param $object
52
59
*
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MessageBird \Objects \Conversation \HSM ;
4
+
5
+ class Currency
6
+ {
7
+ /**
8
+ * @var string $code
9
+ */
10
+ public $ code ;
11
+
12
+ /**
13
+ * @var int $amount
14
+ */
15
+ public $ amount ;
16
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MessageBird \Objects \Conversation \HSM ;
4
+
5
+ class Language
6
+ {
7
+ // Will deliver the message template in the user's device language. If the settings can't be found on the user's
8
+ // device the fallback language is used.
9
+ const FALLBACK_POLICY = 'fallback ' ;
10
+
11
+ // Will deliver the message template exactly in the language and locale asked for.
12
+ const DETERMINISTIC_POLICY = 'deterministic ' ;
13
+
14
+ /**
15
+ * It accepts FALLBACK_POLICY or DETERMINISTIC_POLICY.
16
+ *
17
+ * @var string $policy
18
+ */
19
+ public $ policy ;
20
+
21
+ /**
22
+ * Code can be both language and language_locale formats (e.g. en and en_US).
23
+ *
24
+ * @var string $code
25
+ */
26
+ public $ code ;
27
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MessageBird \Objects \Conversation \HSM ;
4
+
5
+ class Message
6
+ {
7
+ /**
8
+ * @var string $namespace
9
+ */
10
+ public $ namespace ;
11
+
12
+ /**
13
+ * @var string $templateName
14
+ */
15
+ public $ templateName ;
16
+
17
+ /**
18
+ * @var Language $language
19
+ */
20
+ public $ language ;
21
+
22
+ /**
23
+ * @var Params[] $params
24
+ */
25
+ public $ params ;
26
+ }
27
+
28
+
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MessageBird \Objects \Conversation \HSM ;
4
+
5
+ class Params
6
+ {
7
+ /**
8
+ * @var string $default
9
+ */
10
+ public $ default ;
11
+
12
+ /**
13
+ * @var Currency $currency
14
+ */
15
+ public $ currency ;
16
+
17
+ /**
18
+ * Date formatted as RFC3339
19
+ *
20
+ * @var string $dateTime
21
+ */
22
+ public $ dateTime ;
23
+ }
You can’t perform that action at this time.
0 commit comments