How to implement a chat application in codeigniter website? - codeigniter

I need to implement a chat window on my codeigniter website,and the chat option is not like facebook or gmail chat.The Live conversation is entirely between the admin and the user who has logged into the site,ie live chat for direct customer service
Thanks in advance.

A quick search on github gives me this:
https://github.com/Runnable/Chat-Example-App-for-Codeigniter-API-on-PHP
https://github.com/vgoodvin/ci-chat
https://github.com/llbbl/codeigniter-chat
You can think of it like a thread in a forum where someone creating a thread and the other someone make replies.
Depending on how you want to customize your apps, the interaction between the OP and those who will make replies will be rapid.
EDIT 1:
Assuming that you understand how MVC works, you can have something like this:
Your DB Structure:
Table User
Table Session
Table Message
A user can be in many Session (chat room), A message can only be posted to one chat session and a user can send many messages.
In your chat page you will have a to display the conversation, a giant text box where your user can write their message and a submit button.
When a user click the submit button, it will then make an HTTP POST to your controller, where your controller will cleanse the data (i.e. $this->form_validation->set_rules();
If the posted data is valid, send it to your model where it then be stored to your database.
Everytime the chat page is loaded what you want to do is:
Get the chat message for the associated session ID.
Again this is an oversimplified example. You can fork the code from the github i mentioned and try to install it on your local machine.

If you want messaging or chat and specially for codeigniter than use this library, Mahana-Messaging-library-for-CodeIgniter. I have used this, and i preferred you if you are learner. It have it's on database which you can manage and it will integrate in your project easily.

Implemented using Zopim chat widget,which is suitable for both CMS and MVC websites. https://www.zopim.com/

Related

Sending notification to custom teams application

I am working on a custom app that will load data in the personal tab from an external system. Everything works fine when I am on the app.
If the user is on the Calls or Chat tab and the external system is having something new for the user we want to notify the user in the chat or activity feed so that the user can revisit the custom app and review the data.
Please suggest how to achieve it.
Thanks,
Pratap

How to update an existing activity in WebChat

My scenario is: I send card attachments each with an AcceptButton to users. When 1 user clicks on that button, ideally I want to disable all similar buttons (of the same offer) for all users. I am storing conversation details of each user, and I know the ActivityId of each message-with-said-button (it follows a certain string format).
My issue is similar to this and this but for WebChat not Teams.
I did try those solutions but I got the error "Method not allowed" for both UpdateActivityAsync() and DeleteActivityAsync(). Then I read here that UpdateActivity is not supported in WebChat. (But might be available in the future?)
I would like any visual indication that the offer is no longer available. (Right now, they receive an "Offer was already accepted by {UserX}" which would still be in place on top of changing the card/message.)
Is there a way to do this via backChannel? I can trigger an event and pass the ActivityId (tested by showing a simple alert()) but how do I apply changes to that specific activity?
Per this comment in Web Chat's source code and this open issue in the Web Chat repository for adding support for deleteActivity and updateActivity, Update Activity events are not currently supported in Web Chat. Unfortunately, there is currently no way to really update an activity in Web Chat.
Hope this helps!

How to add a dynamic results section to Laravel

I made a laravel app which uses an index method that delivers a collection of the client's available appointments (think hairdresser) to the page (as an api), which I then display using vue/vuetify.
The client is saying they would like the appointments on the page to be dynamic/live eg if someone books an appointment, then all other logged in users will see that appointment disappear from the list on their screen.
I have no idea how I would do this, although I have had one idea - I somehow incorporate node/non-blocking on the server, like a chat room, but only for this part of the app.
Or is there a way to do this with laravel/nginx?
Thanks in advance - I don't know what to search for!
I believe you are looking for Broadcasting (Documentation Link). You would need to:
Configure your broadcasting driver (you could give pusher a try for quick setup and tinkering)
Configure your Laravel backend to dispatch a new event whenever a new appointment is made, (e.g. event(new AppointmentCreated($appointment)) where AppointmentCreated implements the ShouldBroadcast interface. You can combine this with Model Events
Update your frontend to receive your broadcast (Check Laravel Echo). Once you receive a broadcast, update the UI to mark this appointment as unavailable i.e, make it disappear

Questions about saving bot state

I read through this https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-state about saving state data. I have some questions regarding the same:-
Lets take a bot exposed through the browser channel as an example here:-
What is the lifetime of the data stored? For instance when the bot saves data using context.ConversationData.SetValue(..) Is the data purged when the session is over(when the user refreshes the page)?
The From object from Activity has Id and Name. Are these generated by the channel each time a chat session begins? For instance, if I was chatting with bot then refresh the web page, now will my Id and Name have changed?
Same question about conversation. If I refresh the page and begin the conversation again, do I get a new conversation ID?
I read in some blog that if you use dialogs, the dialog stack state is automatically saved in whichever storage you have configured. Is this correct? If so, why? Say I refresh the page, will I be able to retrieve the state of the dialog stack and resume the conversation from there?
If you are giving code samples, request you to give C# samples if possible
Thanks very much in advance!
Hi, I hope below answer will find useful to you :
1.
What is the lifetime of the data stored? For instance when the bot saves data using context.ConversationData.SetValue(..) Is the data
purged when the session is over(when the user refreshes the page)?
ANS:->
As per the guidelines by Bot Framework, State API is in the state of depreciation. you will have to use your own state management service to maintain the state of your Bot. Ref: https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-state
So assuming you are using Table Storage or SQL Database for storing your bot in this case the data will persist as long as your storage account and database available.
2.
The From object from Activity has Id and Name. Are these generated
by the channel each time a chat session begins? For instance, if I
was chatting with bot then refresh the web page, now will my Id and
Name have changed?
ANS:->
This depends on how you initialize the chat. for instance, if you are using
Web chat : It will be empty id.
Skype : It will be skype id and user name
DirectLine : you can define your own id and name as per your need.
3.
Same question about the conversation. If I refresh the page and begin the conversation again, do I get a new conversation ID?
ANS:->
Yes. Every time you refresh your webpage you will be assigned new conversationId but in case of DirectLine you can use the previous conversation id to maintain the history of your conversation. you can store the conversation id in local storage or in browser's cookies and read whenever you feel to load the chat history. If you don't need history to be preserved then I suggest let webchannel handle its own ids.
4.
I read in some blog that if you use dialogs, the dialog stack state is automatically saved in whichever storage you have configured. Is this correct?
ANS:->
Yes.
5.
If so, why? Say I refresh the page, will I be able to retrieve the state of the dialog stack and resume the conversation from there?
ANS:->
As hinted earlier, you will need to migrate your bot to use DirectLine API instead of webchat channel. As webchat doesn't support history so DirectLine.
Please refer the guidelines provided by Microsoft and Samples provided on GitHub.
https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-concepts
Quick answers:
As far as I know, there is no purge. And you can check the implementations of Azure DocumentDbBotDataStore or TableBotDataStore here. Based on my implementations, I saw there is a Timestamp column in the stored data so you could do cleanup based in that.
Generation of Id and Name fields (for From, but also for Recipient given the message origin / destination): yes they depend on the channel. I made a detailed answer about on SO: Bot Framework User Identification
Yes in the webchat's case
Yes, the dialog stack state is saved so that you can continue your conversation. "Say I refresh the page, will I be able to retrieve the state of the dialog stack and resume the conversation from there?": if you have the same details (channelId + conversationId, userId) you should yes. The exception is the webchat / directLine where you have to implement the fact that you keep the same IDs. For other channels like Slack, Facebook Messenger etc, these items remains the same and the dialog can continue where it stops on the previous messages exchange

Instant messages in MVC application

I need your help to solve next issue: I am developing MVC application and want to send instant messages between users. This message will ne standard - it's like notification. I am thinking about two optins:
use XMPP protocot, but I don't need the huge amount of options it could provide, I need just basic functionality I've discribed;
have some static array in MVC application with users invitations were send to and ajax function which will call controller action, check if user is in static list. If yes - make message visible on the page. And plus do page autoupdate. But I am not sure about this becouse array will be called very often.
What do you think, guys? Do you have any ideas? I will be very thankfull for any help!
You may take a look at SignalR.
Also checkout Jabbr which is built on SignalR:
https://github.com/davidfowl/JabbR
This is a chat application written by the author of SignalR David Fowler.
You can set jquery timer to update messages with ajax. And when user writes message , it can be saved in Cache or in database if you want to save it permanently.

Resources