KIK Card - sending message directly - ios

I'm building new KIK Card and i would like to create button which will send messages to 5 people selected from kik.pickUsers Is there any command that allow me to send messages directly, without pressing button "send"? This is my code:
cards.kik.pickUsers({
minResults: 5, // number >= 5
maxResults: 99 // number < 99
}, function (users) {
if (!users) {
return;
}
users.forEach(function (user) {
cards.kik.send(user.username, {
title: 'Message',
text: 'Text!!!'
});
});
});

Messages cannot be sent directly without user consent (via pressing the "send" button) - this is a tactic to avoid apps spamming content messages on behalf of the user.
Regarding sending to multiple people, as of this writing you can only send a message to a group if the conversation already exists in Kik.
Iterating over the array of users returned from the picker and trying to use kik.send() for each will only work for the first user in the array.
The Pop app on Kik has a good implementation to overcome this for inviting friends to use the app. This may or may not be relevant depending on what you are developing.

Related

Twilio SWIFT API get consumed messages always returns 0

I want to display next to a chat channel the number of messages a channel has that have been unconsumed or unread (I assume this is what unconsumed means?)
Currently I send messages to a channel that two users are subscribed to , a private chat. Then before opening up the chat window I check the channel for unconsumed messages, but it always say 0 messages even if I call setNoMessagesConsumedWithCompletion.
I am using the Swift API...What do I need to do to find out how many messages in my channel have not been read yet? At what point do they become read? (when the user opens up a chat channel and requests to getLastWithCount?)
I read in the docs you have to set something called the consumption horizon to get unconsumed message, but I don't know how you do that in SWIFT API https://www.twilio.com/docs/chat/consumption-horizon also this was for Javascript API so perhaps it is easier with Swift Api?
I figured out the solution. As per the documentation you need to update the last consumed message index. So for example if the user has a chat window open you need to record for that user (or instance of the Chat Client) what was the last message they saw before they close their chat. I am storing all the messages in a message array and update the last consumed message index with the length of the array of messages:
generalChannel?.messages?.setLastConsumedMessageIndex(NSNumber.init(value: self.messages.count), completion: { (result, count) in
if !result.isSuccessful() {
print(result.error.debugDescription)
}
})
Then if you send messages to that channel when the user is not in the channel these will be recorded as unconsumed, you can get the number by calling:
channel.getUnconsumedMessagesCount(completion: { (results, numberUnconsumed) in
print(numberUnconsumed)
})

Twilio chat client channels list

I am trying to create a simple chat app between 2 users, using twilio js api.
The idea is that I know that two users will have to chat with each other, and I want to create a channel specifically for the chat between them both.
So when a user logs in, I want to search the channel by it's name:
if it exist already, it means that the other user is already logged, and I want to join this channel.
else, I want to create a channel by this specific name, and wait for the other user.
I tried 2 alternatives:
1. chat client.
2. IPMessaging client.
I am trying to user this function:
chatClient.getChannels().then(function (channels){ // search for the channel I need // }
But for chat channel I get the following error:
twilio TypeError: chatClient.getChannels is not a function
So with an IPMessaging client it all works well, but I can't trigger events of user typing, which are important for my app:
chatChannel.on('typingStarted', function(){
console.log('user started typing')
});
chatChannel.on('typingEnded', function(){
console.log('user stopped typing')
});
Should this events be possible to trigger for IPMessaging Client?
If not, how can I get the channels list for a chat client?
Thank you
You can trigger typing indicators with IPMessaging (Programmable chat):
https://www.twilio.com/docs/api/chat/guides/typing-indicator
//intercept the keydown event
inputBox.on('keydown', function(e) {
//if the RETURN/ENTER key is pressed, send the message
if (e.keyCode === 13) {
sendButton.click();
}
//else send the Typing Indicator signal
else {
activeChannel.typing();
}
});
That same event can be triggered for members, and not only channels.
https://media.twiliocdn.com/sdk/js/chat/releases/0.11.1/docs/Member.html

Facebook plugin for phonegap ios application - share on the wall

I am trying to share from my phonegap ios application. I use this code to post to my facebook wall
var facebookConnectPluginPostToTheWall = function () {
var options =
{
method: "feed",
name: "Shared via my cool app",
message: "This is a post shared from my app. I have earned 300xps."
};
facebookConnectPlugin.showDialog(options,
function (response) {
alert(JSON.stringify(response))
});
};
And it shares the post to the facebook, but I can't make it work with these preset values for message, title etc. It just shares the text I enter in the popup shown after calling this function. I hope someone can help with this.
The feed dialog does not accept any prefilled messsage - but prefilling is not allowed anyway, the message always must be 100% user generated.
If you want to post without a dialog, you have to authorize the user with publish_actions and use the feed API: https://developers.facebook.com/docs/graph-api/reference/v2.2/user/feed
But again, prefilling the message is not allowed. Read the platform policy for more information: https://developers.facebook.com/policy/

Update database record after user has logged in

What I'm trying to achieve is similar to how the login works here on StackOverflow. If you are not logged in you can still see questions but if you try to +1 some of the questions you are asked to login. When you do login your +1 is remembered and added to the question.
This is my scenario:
A user search for members and selects one - login is not required
After selecting a member the user is redirected to a feedback page where the user can write a feedback message to the member
The user writes the feedback and click Save
No matter if the user is logged in or not the feedback is saved
If the user is not logged in a popup will open where the user will be asked to login
After the user logs in the feedback, created in step 4, will be updated with the user's Id
The user is redirected back to the search page from step 1
I'm stuck at step 6. I can't figure out what the best way of getting the Id of the logged in user and then update the feedback message after that.
This code represents step 5. It simply sends the feedback message to the controller and saves it. After the message is .done I call the login popup. The return message.Data contains the Id of the feedback message (which just has been created) and which I need after the user logs in.
function saveModel(feedbackMessage) {
cc.Ajax.jpost(urlSave, { feedbackMessage: feedbackMessage })
.done(function (message, textStatus, jqXHR) {
if (message.Status == 2) { // user not logged in
openSignInModal(message.Data);
}
})
}
This code represents step 6. The returned data is a partial view containing the login page.
function openSignInModal(feedbackId) {
var url = '/Account/LoginPartial';
$.ajax({
url: url,
type: 'get',
data: { returnUrl: '/Subscriber/Search', subTitle: feedbackNotSignedIn, modalTitle: '' },
success: function (data, textStatus, jqXHR) {
$('#pc_modal_container').html(data);
$('#pc_modal').modal('show');
},
});
}
If the user logs in then I want to get the Id of the user and update the feedback message with the logged in user's id (similar to what I explained in the beginning with StackOverflow).
My questions are:
Where should I keep the feedback message Id which I get in step 4 so I can use it to update the feedback message?
When the user is logged in and I want to update the feedback message how can I handle this best? I know I could store it in TempData but I don't really see this at the best option, or is it?
I have tried to find examples online but nothing that fits this well enough. Does anyone know of any examples which could fit this scenario?
Thanks
Try this process. It do not have any technical detail, but I believe it will be enougth to accomplish your goal.
During the feedback POST, preserve the feedback post ID into a Cache variable, as PendingFeedBacks
Make these cached data availabe only to current session, and with low expiration period
Somewhere, if the user is authenticated, and there is any pending feedback to be adopted, do it!
I do not believe that this should be the best solution, but it will do the trick.

When both users are in chat room, messages are still marked unread

I'm having some trouble with Quickblox chat. Whenever two users are both logged in and both joined in the same chat room, messages that are sent between the two users are not marked as read. When I back out of the room to the dialogs list and the dialogs are refreshed, it says that there are unread messages even though I was in the room and I was receiving the messages live.
Is there a certain call that I must make to let it be known that the received messages should be marked as read? I am developing in iOS.
Thanks.
User has to read message to mark it as read
NSString *dialogID = #"53d10eede4b02f496c21549f";
NSArray *mesagesIDs = #[#"53aabe15e4b077ddd43e7fd3", #"53aabe15e4b077ddd43e7fd7"];
[QBChat markMessagesAsRead:mesagesIDs dialogID:dialogID delegate:self];
In iOS you can use:
QBRequest.markMessagesAsRead(Set<String>?, dialogID: String, successBlock:
{
(QBResponse) in code
})
{
(QBResponse) in code
}

Resources