-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to send message if recipient is offline #141
Comments
You can pass a MessageConfig with |
is this correct? // msg for nmobile
var msg_config = nkn.MessageConfig{
Unencrypted: false,
NoReply: true,
MaxHoldingSeconds: 600,
MessageID: nil,
TxPool: false,
Offset: 0,
Limit: 1000,
}
msg := DataMsg{
ContentType: "text",
ID: uuid.New().String(),
Content: "64955",
IsPrivate: true,
Timestamp: time.Now().UnixMilli(), // Equivalent to new Date().getTime()
}
// Marshal the map to JSON
msg_json, err := json.Marshal(msg)
if err != nil {
return err
}
log.Println(string(msg_json))
onReply, err := fromClient.Send(nkn.NewStringArray("4e90a1235f1fda3ba5328189fdb7c225fb621afeb660b0cde3dd8575a10fecc8"), string(msg_json), &msg_config)
if err != nil {
return err
} I am not sure about
|
That's right. Actually you can simply do:
and leave the rest fields unset, the sdk will automatically use default values for those. |
OK, last question I have enabled Message Notification for a Sender in recipient's nMobile, how to use sdk for sender to use that feature? |
That part cannot be done by the SDK because of iOS/Android restrictions. The only way to send push notification to iOS/Android device is to get target device's push notification token, and use that token to send notification through Apple/Google push notification server. So if you want to do it, you will need to save recipient's push notification token (you will receive a NKN message when recipient enables notification for you in nMobile), and use that token to send push notification yourself. |
@yilunzhang thanks for the reply, so I have tried to get the push notification token with following code, reply := <-onReply.C
isEncryptedStr := "unencrypted"
if reply.Encrypted {
isEncryptedStr = "encrypted"
}
timeResponse := time.Now().UnixNano() / int64(time.Millisecond)
log.Println("Got", isEncryptedStr, "reply", "\""+string(reply.Data)+"\"", "from", reply.Src, "at", timeResponse, "ms") after I toggle the Message Notification switch, I did not see log.Println on terminal, how should I modify my code? |
you need to make sure the address you are listening at in the sdk and the address you are talking to in nMobile are the same. Then you can try printing all messages received in sdk and see if you can receive messages when you send messages and toggle notifications in nMobile |
OK, now I have got two different message type from nMobile, type 1
type 2
I noticed and for type 1 message from nMobile, should I ignore it? |
Yeah APNS is short for Apple Push Notification Service. And you can ignore messages you don't need now. |
@yilunzhang after some further reading and research, here is what I have found. APNS_URL: Implications for 3rd Party Service ProvidersIf you are a third-party service provider for a chat app, these credentials are still necessary for sending push notifications on behalf of your clients (the app developers). Here’s how it typically works: Client Configuration: Your clients (the chat app developers) must provide you with their APNS_KEY_ID, APNS_TEAM_ID, and the path to their .p8 file. They would also need to ensure that their app is configured correctly in their Apple Developer account to support push notifications. Sending Notifications: When you receive a request to send a notification, you would use the provided credentials along with the device token of the target user (which you would have received from the client’s app) to construct and send the notification request to APNs. |
Hi, I have been testing nkn-sdk-go, and got a problem of sending message to nMobile when recipient is offline.
following code is my current implementation, which only works when recipient's APP is active on screen.
file
send.go
test:
go run send.go
change following recipient for test.
4e90a1235f1fda3ba5328189fdb7c225fb621afeb660b0cde3dd8575a10fecc8 ( copied from nMobile )
The text was updated successfully, but these errors were encountered: