Skip to content

Commit

Permalink
Merge pull request #2 from FabrizioBrancati/greetings
Browse files Browse the repository at this point in the history
Adding greetings for Messenger
  • Loading branch information
FabrizioBrancati authored Mar 10, 2017
2 parents 2fa6861 + 0cf4395 commit 4f88489
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.<br>
---

### 2.X Releases
- `2.1.x` Releases - [2.1.0](#210---big-greetings)
- `2.0.x` Releases - [2.0.0](#200---sell-me-something)

### 1.X Releases
Expand All @@ -18,6 +19,12 @@ All notable changes to this project will be documented in this file.<br>

---

## [2.1.0](https://github.com/FabrizioBrancati/SwiftyBot/releases/tag/2.1.0) - Big Greetings
### 10 Mar 2017
### Added
- Added greetings for Facebook Messenger


## [2.0.0](https://github.com/FabrizioBrancati/SwiftyBot/releases/tag/2.0.0) - Sell Me Something
### 07 Feb 2017
### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/FabrizioBrancati/SwiftyBot.svg?branch=master)](https://travis-ci.org/FabrizioBrancati/SwiftyBot)
[![Codebeat Badge](https://codebeat.co/badges/5c994b12-c55e-46ec-b870-1c42154289a3)](https://codebeat.co/projects/github-com-fabriziobrancati-swiftybot)
[![Version](https://img.shields.io/badge/version-2.0.0-blue.svg)](https://developer.apple.com/swift/)
[![Version](https://img.shields.io/badge/version-2.1.0-blue.svg)](https://developer.apple.com/swift/)
[![Language](https://img.shields.io/badge/language-Swift%203.0-orange.svg)](https://developer.apple.com/swift/)
[![Platform](https://img.shields.io/badge/platform-Linux%20/%20macOS-ffc713.svg)](https://developer.apple.com/swift/)
[![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/FabrizioBrancati/SwiftyBot/blob/master/LICENSE)
Expand Down
23 changes: 23 additions & 0 deletions Sources/SwiftyBot/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ guard telegramSecret != "" || (messengerSecret != "" && messengerToken != "") el
throw BotError.missingAppSecrets
}

// MARK: - Helpers

/// Detector helper struct.
extension String {
/// Detect if the message has greetings.
///
/// - Returns: Returns true if the message has greetings, otherwise false.
func hasGreetings() -> Bool {
let message = self.lowercased()
if message.contains("hi") ||
message.contains("hello") ||
message.contains("hey") ||
message.contains("hei") ||
message.contains("ciao") {
return true
}
return false
}
}

// MARK: - Telegram bot

/// Setting up the POST request with Telegram secret key.
Expand Down Expand Up @@ -335,6 +355,9 @@ droplet.post("messenger", messengerSecret) { request in
} else if text.isEmpty {
/// Set the response message text.
response = Messenger.message("I'm sorry but your message is empty 😢")
/// The user greeted the bot.
} else if text.hasGreetings() {
response = Messenger.message("Hi!\nThis is an example on how to create a bot with Swift.\nIf you want to see more try to send me \"buy\", \"sell\" or \"shop\".")
/// The user wants to buy something.
} else if text.lowercased().range(of: "sell") || text.lowercased().range(of: "buy") || text.lowercased().range(of: "shop") {
do {
Expand Down

0 comments on commit 4f88489

Please sign in to comment.