Class: WhatsAppNotifier::MessagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- WhatsAppNotifier::MessagesController
- Defined in:
- app/controllers/whatsapp_notifier/messages_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /send — single-recipient send for the current user.
Instance Method Details
#create ⇒ Object
POST /send — single-recipient send for the current user
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/whatsapp_notifier/messages_controller.rb', line 9 def create to = params[:to] || params[:phone] or raise ActionController::ParameterMissing, "to (or phone)" = params.require(:message) media_url = params[:media_url] result = WhatsAppNotifier.deliver( to: to, body: , metadata: { user_id: whatsapp_notifier_user_id, media_url: media_url } ) if result.success? render json: { success: true, message_id: result. } else render json: { success: false, error: result. }, status: :unprocessable_entity end rescue ActionController::ParameterMissing => e render json: { success: false, error: e. }, status: :bad_request rescue StandardError => e render json: { success: false, error: e. }, status: :internal_server_error end |