Skip to content
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

[Draft] Client Side Bot Messages #823

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/src/components/billing/BillingOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {LITE_PRICE, STARTER_PRICE, TEAM_PRICE} from '../../constants';
import {env} from '../../config';
import './Billing.css';

const stripe = loadStripe(env.REACT_APP_STRIPE_PUBLIC_KEY);
const stripe = loadStripe('undefined');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was crashing the app

it should be fixed before removing the draft tag


const BillingBreakdownTable = ({
loading,
Expand Down
33 changes: 33 additions & 0 deletions lib/chat_api_web/channels/conversation_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,35 @@ defmodule ChatApiWeb.ConversationChannel do
{:reply, {:ok, payload}, socket}
end

def handle_in("bot:shout", payload, socket) do
with %{conversation: conversation} <- socket.assigns,
%{id: conversation_id, account_id: account_id} <- conversation,
{signature, payload} <- Map.pop(payload, "signature"),
user_id <- user_id_of_signature(signature),
{:ok, message} <-
payload
|> Map.merge(%{
"conversation_id" => conversation_id,
"account_id" => account_id,
"user_id" => user_id
})
|> Messages.create_message() do
case Map.get(payload, "file_ids") do
file_ids when is_list(file_ids) -> Messages.create_attachments(message, file_ids)
_ -> nil
end

message = Messages.get_message!(message.id)

broadcast_new_message(socket, message)
else
_ ->
broadcast(socket, "shout", payload)
end

{:noreply, socket}
end

def handle_in("shout", payload, socket) do
with %{conversation: conversation} <- socket.assigns,
%{id: conversation_id, account_id: account_id} <- conversation,
Expand Down Expand Up @@ -161,4 +190,8 @@ defmodule ChatApiWeb.ConversationChannel do
_ -> false
end
end

defp user_id_of_signature(_signature) do
1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should receive the message, signature and validate it

if valid, return an user_id so that the message looks like it's from an agent?

end
end