Skip to content

Commit 0dfe8b0

Browse files
Merge pull request #37 from appwrite/dev
Fix msg91 params
2 parents 3f59fbc + 19185d9 commit 0dfe8b0

File tree

8 files changed

+46
-23
lines changed

8 files changed

+46
-23
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-kotlin.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-kotlin.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-1.5.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.5.4-blue.svg?style=flat-square)
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
88

@@ -39,7 +39,7 @@ repositories {
3939
Next, add the dependency to your project's `build.gradle(.kts)` file:
4040

4141
```groovy
42-
implementation("io.appwrite:sdk-for-kotlin:5.0.0")
42+
implementation("io.appwrite:sdk-for-kotlin:5.0.1")
4343
```
4444

4545
### Maven
@@ -50,7 +50,7 @@ Add this to your project's `pom.xml` file:
5050
<dependency>
5151
<groupId>io.appwrite</groupId>
5252
<artifactId>sdk-for-kotlin</artifactId>
53-
<version>5.0.0</version>
53+
<version>5.0.1</version>
5454
</dependency>
5555
</dependencies>
5656
```

docs/examples/java/messaging/create-msg91provider.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Messaging messaging = new Messaging(client);
1212
messaging.createMsg91Provider(
1313
"<PROVIDER_ID>", // providerId
1414
"<NAME>", // name
15-
"+12065550100", // from (optional)
15+
"<TEMPLATE_ID>", // templateId (optional)
1616
"<SENDER_ID>", // senderId (optional)
1717
"<AUTH_KEY>", // authKey (optional)
1818
false, // enabled (optional)

docs/examples/java/messaging/update-msg91provider.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ messaging.updateMsg91Provider(
1313
"<PROVIDER_ID>", // providerId
1414
"<NAME>", // name (optional)
1515
false, // enabled (optional)
16+
"<TEMPLATE_ID>", // templateId (optional)
1617
"<SENDER_ID>", // senderId (optional)
1718
"<AUTH_KEY>", // authKey (optional)
18-
"<FROM>", // from (optional)
1919
new CoroutineCallback<>((result, error) -> {
2020
if (error != null) {
2121
error.printStackTrace();

docs/examples/kotlin/messaging/create-msg91provider.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ val messaging = Messaging(client)
1212
val response = messaging.createMsg91Provider(
1313
providerId = "<PROVIDER_ID>",
1414
name = "<NAME>",
15-
from = "+12065550100", // optional
15+
templateId = "<TEMPLATE_ID>", // optional
1616
senderId = "<SENDER_ID>", // optional
1717
authKey = "<AUTH_KEY>", // optional
1818
enabled = false // optional

docs/examples/kotlin/messaging/update-msg91provider.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ val response = messaging.updateMsg91Provider(
1313
providerId = "<PROVIDER_ID>",
1414
name = "<NAME>", // optional
1515
enabled = false, // optional
16+
templateId = "<TEMPLATE_ID>", // optional
1617
senderId = "<SENDER_ID>", // optional
17-
authKey = "<AUTH_KEY>", // optional
18-
from = "<FROM>" // optional
18+
authKey = "<AUTH_KEY>" // optional
1919
)

src/main/kotlin/io/appwrite/Client.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class Client @JvmOverloads constructor(
5757
init {
5858
headers = mutableMapOf(
5959
"content-type" to "application/json",
60-
"user-agent" to "AppwriteKotlinSDK/5.0.0 ${System.getProperty("http.agent")}",
60+
"user-agent" to "AppwriteKotlinSDK/5.0.1 ${System.getProperty("http.agent")}",
6161
"x-sdk-name" to "Kotlin",
6262
"x-sdk-platform" to "server",
6363
"x-sdk-language" to "kotlin",
64-
"x-sdk-version" to "5.0.0",
64+
"x-sdk-version" to "5.0.1",
6565
"x-appwrite-response-format" to "1.5.0",
6666
)
6767

src/main/kotlin/io/appwrite/ID.kt

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
package io.appwrite
22

3+
import java.time.Instant
4+
import kotlin.math.floor
5+
import kotlin.random.Random
6+
37
class ID {
48
companion object {
9+
// Generate an hex ID based on timestamp
10+
// Recreated from https://www.php.net/manual/en/function.uniqid.php
11+
private fun hexTimestamp(): String {
12+
val now = Instant.now()
13+
val sec = now.epochSecond
14+
val usec = (System.nanoTime() / 1000) % 1000
15+
16+
val hexTimestamp = "%08x%05x".format(sec, usec)
17+
18+
return hexTimestamp
19+
}
20+
521
fun custom(id: String): String
622
= id
7-
fun unique(): String
8-
= "unique()"
23+
// Generate a unique ID with padding to have a longer ID
24+
fun unique(padding: Int = 7): String {
25+
val baseId = ID.hexTimestamp()
26+
val randomPadding = (1..padding)
27+
.map { Random.nextInt(0, 16).toString(16) }
28+
.joinToString("")
29+
30+
return baseId + randomPadding
31+
}
932
}
10-
}
33+
}

src/main/kotlin/io/appwrite/services/Messaging.kt

+10-10
Original file line numberDiff line numberDiff line change
@@ -941,9 +941,9 @@ class Messaging(client: Client) : Service(client) {
941941
*
942942
* @param providerId Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
943943
* @param name Provider name.
944-
* @param from Sender Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.
945-
* @param senderId Msg91 Sender ID.
946-
* @param authKey Msg91 Auth Key.
944+
* @param templateId Msg91 template ID
945+
* @param senderId Msg91 sender ID.
946+
* @param authKey Msg91 auth key.
947947
* @param enabled Set as enabled.
948948
* @return [io.appwrite.models.Provider]
949949
*/
@@ -952,7 +952,7 @@ class Messaging(client: Client) : Service(client) {
952952
suspend fun createMsg91Provider(
953953
providerId: String,
954954
name: String,
955-
from: String? = null,
955+
templateId: String? = null,
956956
senderId: String? = null,
957957
authKey: String? = null,
958958
enabled: Boolean? = null,
@@ -962,7 +962,7 @@ class Messaging(client: Client) : Service(client) {
962962
val apiParams = mutableMapOf<String, Any?>(
963963
"providerId" to providerId,
964964
"name" to name,
965-
"from" to from,
965+
"templateId" to templateId,
966966
"senderId" to senderId,
967967
"authKey" to authKey,
968968
"enabled" to enabled,
@@ -991,9 +991,9 @@ class Messaging(client: Client) : Service(client) {
991991
* @param providerId Provider ID.
992992
* @param name Provider name.
993993
* @param enabled Set as enabled.
994-
* @param senderId Msg91 Sender ID.
995-
* @param authKey Msg91 Auth Key.
996-
* @param from Sender number.
994+
* @param templateId Msg91 template ID.
995+
* @param senderId Msg91 sender ID.
996+
* @param authKey Msg91 auth key.
997997
* @return [io.appwrite.models.Provider]
998998
*/
999999
@JvmOverloads
@@ -1002,19 +1002,19 @@ class Messaging(client: Client) : Service(client) {
10021002
providerId: String,
10031003
name: String? = null,
10041004
enabled: Boolean? = null,
1005+
templateId: String? = null,
10051006
senderId: String? = null,
10061007
authKey: String? = null,
1007-
from: String? = null,
10081008
): io.appwrite.models.Provider {
10091009
val apiPath = "/messaging/providers/msg91/{providerId}"
10101010
.replace("{providerId}", providerId)
10111011

10121012
val apiParams = mutableMapOf<String, Any?>(
10131013
"name" to name,
10141014
"enabled" to enabled,
1015+
"templateId" to templateId,
10151016
"senderId" to senderId,
10161017
"authKey" to authKey,
1017-
"from" to from,
10181018
)
10191019
val apiHeaders = mutableMapOf(
10201020
"content-type" to "application/json",

0 commit comments

Comments
 (0)